Questions tagged [algorithms]

In mathematics and computer science, an algorithm is an effective method expressed as a finite list of well-defined instructions for calculating a function. Algorithms are used for calculation, data processing, and automated reasoning.

Filter by
Sorted by
Tagged with
0 votes
2 answers
662 views

Algorithm to find minimum number of elements that occur in all sets

I have n sets that each contain some elements, for example: {2, 3}, {6, 3}, {2, 7, 3}, {7} Now the goal is to find the minimum number of elements that occur in all sets. For this example it would be 2 ...
  • 109
0 votes
1 answer
125 views

Versioning of data handling pipeline elements

I have developed a custom-made Python package, which provides 2 classes to play with: Stage and Step. They operate based on a Chain of Responsibility design pattern, and behave in a way where: Both ...
  • 109
-4 votes
4 answers
2k views

Time efficient way to count pairs in an array whose sum is divisible by a specific number?

Given an array of integers, we want to find how many explicit pairs can be made such that their sum is divisible by 60. The pairs are not necessarily non-unique. For example, let's say the input into ...
  • 1,349
3 votes
1 answer
166 views

Nested loop complexity

I am working through MIT 6.006 OpenCourseWare as taught in Fall 2011. Problem 1.2c asks for the time complexity of an algorithm1 which finds a peak element (i.e. all neighbors are less than or equal) ...
0 votes
1 answer
69 views

Pubsub model - publisher broadcast to remote subscribers

With a single publisher(go-routine) and multiple subscribers(go-routine) on same machine, below message hub help create pubsub model: type PublisherHub struct { subscribers map[*subscribmediator....
  • 2,235
0 votes
1 answer
1k views

Efficient way to find Xor of pairs with given target X in a range 0 to K

I came across a problem: given an array (can be huge 10^8) and an integer, K, find the count of pairs in the array whose Xor equal to each value in the range 0 to K. eg: Arr = 1 2 3 K = 2 since K=...
12 votes
2 answers
884 views

Data structure for multi key range queries

I need a data structure that gives the best performance for multi-key range lookups. I do not need to update/insert/delete. This will be immutable. The use case is in-memory filtering of values over ...
20 votes
6 answers
4k views

Using a different algorithm depending on the size of the input

I recently finished a course on advanced algorithms, and another on complexity & computability theory, and in the past few days my mind has been somewhat preoccupied by this question. Why don't we ...
  • 335
0 votes
0 answers
70 views

Time-indexed "array" of time spans

I have a list of objects that have durations, ProcedurePart Start: double Stop: double Instructions: string they occur sequentially after each other: stepOne stepTwo ...
-4 votes
1 answer
469 views

Better way to process huge files

I have a huge csv file and I have to process that file and do some data manipulation. Right now I'm reading/loading the file in buffer and then doing the data processing work. I find this approach ...
-2 votes
2 answers
238 views

Is looping an array to compare to itself considered O(n^2)? [duplicate]

Often when I'm doing an operation comparing an array to itself, I write code along these lines: function operation (array) { for (let i = 0; i < array.length; i++) { for (let j = i + 1; j <...
4 votes
2 answers
382 views

How to show fluctuating data smoothly and accurately?

I am working on a project in which I have to read data from liquid level sensor installed in tank which measures fluid level and sends output in millivolt. The device has predefined ranges of voltage ...
1 vote
3 answers
1k views

Need help finding an efficient way to group the keys in a dictionary into buckets defined by the values in the dictionary?

I have a dictionary in the form of Dictionary<int, List<int>> The problem is that I need to group the keys together into buckets defined by the value (List<int>). It is easier to ...
  • 139
3 votes
5 answers
351 views

Applying function to file line by line or read entirely into structure first?

I've often found myself with the need to develop tools that process large files over a network and perform an operation to every element in that file. An element may be an individual line or an object ...
  • 997
-3 votes
2 answers
815 views

Which hash algorithm is best for speed and identical hashes. (a lot of collisions)

I'm searching an existing hash function or trying to make a hash function that has a lot of collisions. Regularly a hash is used for it's ability to create unique hashes for hash tables or security ...
1 vote
0 answers
137 views

Rectangle packing / Bin packing with multiple frames

I have multiple rectangular frames, with different fixed heights. The width should be minimized and there is a maximum width. Then there are many different smaller rectangles. These should be packed ...
-5 votes
1 answer
46 views

Choosing 2 or 3 values out 3 values after calculating their closeness

I want to find a specific algorithm to choose either 2 or 3 out of 3 given values. Like if I have a set of values 10,11,12 all three are close enough so I will calculate the mean of the value and ...
2 votes
2 answers
259 views

Collaborative graph exploration algorithm

Given a minimum spanning tree in an unweighted graph of (10 .. 500) vertices and (vertice_count .. 1000) edges. Each vertex can have up to 6 edges. Given K agents/bots/processes/etc.., all starting ...
4 votes
3 answers
266 views

How to return "debugging" information during the execution of an algorithm

I was recently tasked with thinking about returning optional tracing information about the execution of a complex algorithm. It's the kind of data you need to analyse the inner workings - a bit like ...
  • 157
5 votes
5 answers
777 views

How can billion integer ids be stored and specific ones checked for existence most efficiently? (persistent solution, not just in-memory)

Let me preface this by saying that I am familiar with RDBMS. I have a solution using mysql/mariadb but I am not happy with the efficiency of the solution so I'm looking for alternatives. I'm trying ...
-4 votes
2 answers
2k views

Booking Availability Algorithm

I've been tasked with creating a booking system and need to figure out when rooms are available at specific time slots on each day. There are 5 available meeting rooms that can be booked at fixed ...
user avatar
0 votes
2 answers
134 views

How to minimize size of data given the need for a null pointer?

So I don't know how to formulate this clearly, as it's quite confusing. Hence the reason for asking this question, to overcome the confusion. I will do my best to make it clear, but part of the ...
  • 2,422
2 votes
2 answers
214 views

Time complexity for a small code

I'm trying to find the time complexity for the following code. N= number of elements in array D= a constant: D>1 V= a constant: V>1000 counter=1; //the maximum value of the counter is N/D. ...
  • 37
-3 votes
2 answers
111 views

Recursion + Stack/Queue usage in practical life implementation [closed]

I am very new to Data Structures and Algorithms. I want to use recursion + stack/queue in a grocery store inventory program that I am making. However, I can't come up with any good ways of using ...
1 vote
2 answers
216 views

Algorithm for rule-based sorting?

I am trying to plant a garden. Certain plants are good for some plants and bad for others, and I am trying to find the best order of plants: most adjacent friends and no adjacent foes, as defined in ...
  • 119
-4 votes
1 answer
298 views

What is the worst case Time Complexity for only the Divide Portion of the Merge Sort Algorithm?

Please, consider the below merge sort algorithm. Here we start with a divide portion which splits the array into halves and we do recursive operation on each half separately. I have ignored the merge ...
-1 votes
1 answer
49 views

Resolving Dependencies and Incompatibilities Deterministically

Problem Description I'm working in Python and I've been having a problem designing something to handle the following (abstracted) system: I have some objects (lets call them Nodes) that can be in ...
  • 3
0 votes
0 answers
78 views

Assigning weights dynamically to ensure equal distribution

Scenario:- The load balancer distributes traffic to backends with a simple round-robin mechanism. With default config, each backend is assigned weight "1" so all backends are given equal chance of ...
-4 votes
1 answer
55 views

Choose a most probable value from the list based on some text [closed]

Im looking for a good way to find a value from the given list based on a text. Example: This computer has 16GB ram and with the best processor in it. Case is made from aluminium. And I have ...
  • 103
3 votes
4 answers
414 views

An algorithm for self picking teams

Say I have 100 users, each with varying strength, and each with a top 5 set of "preferred teammates" and a top 5 set of "preferred enemies". I want to sort the users into two teams. User { int Id;...
  • 582
0 votes
1 answer
78 views

Design Algorithms and Data Structures Around a Lack of Fast Integer Division

I had begun scouring my code for optimization opportunities (execution speed, data parallelism, workload parallelism) yesterday when I noticed that there are very few opportunities for speeding up ...
  • 145
1 vote
1 answer
83 views

Using Builtin Method vs Manual Implementation

I work in a DevOps role and mainly write glue code and OS-level automation. I've rarely needed to deviate from existing language implementations or "reinvent the wheel" in the small programs I've ...
7 votes
7 answers
2k views

Best algorithm to sort tasks by priorities by a human

I have developed a task management tool. And some task lists can be very large. (I have myself more than 300 tasks to do). I would like to do some task reviews from time to time as the tasks pile up ...
  • 205
-1 votes
1 answer
55 views

Algorithm for subjective ranking by many people

My friends and I are trying to figure out which one of our professor's would win in a fist fight. (ie, 2 profs would fight at a time, and the victors of those fights would then fight, etc. until there ...
-3 votes
1 answer
87 views

Shopping Cart Offers

I have been wondering about this issue for quiet some time now. I find interesting and I have not been able to come up with a solution. This must be seen in a context of a shopping cart where you can ...
-4 votes
1 answer
104 views

Is there any formula or trick to count how many times a statement inside a nested loop gets executed?

I am modifying a software which is for trash collection. While reading the code, I asked myself is there any formula or trick to quickly calculate the number of time the statement gets executed inside ...
3 votes
3 answers
1k views

What is the right algorithm to match regex on a stream?

I'd like to match a regex pattern on a stream, but I am not sure what algorithm to use. I certainly don't want to load the entire file into memory. I tried to figure out how to do this, but I have ...
  • 1,161
0 votes
1 answer
83 views

Transitive matching in streaming application

Problem A streaming application should perform matching transitively i.e. if A == B & B == C then A == C Current Implementation Application accepts domain objects in a streaming fashion and ...
0 votes
1 answer
76 views

Booking problem

The initial task was to find very quickly, free time for resources, let say - hotel rooms, services availability. I came with following model: Let say we have 24h in 1 day, and 365(366) days in a ...
  • 101
1 vote
3 answers
674 views

Comparing whether two very large text contents are different or not efficiently

I have a MySQL database with a column Body MEDIUMTEXT. Until now I used to only store the contents into it. There was no update option for the users of the application. Now, I wanted to add an update ...
1 vote
0 answers
149 views

How can i implement two way asymmetric encryption for my app and backend server?

I'm planning to setup a hybrid encryption procedure in my app. So basically i did encryption for data send from client to server using this method, now i'm confused on how to encrypt data send from ...
-2 votes
1 answer
147 views

Smooth out requests to rate limitted API

wasted requests not enough time for those requests | | | | (1) |-x--x-----------------x----x--x--x| x x (executing ...
  • 101
1 vote
1 answer
233 views

Inefficient Pseudocode

I have problems to write my first simple pseudocode. The input of the algorithm is an ontology which contains axioms and an inference set, exactly an inference is defined as an object with set of ...
2 votes
0 answers
158 views

Algorithm to search very long blacklist in another very long data set

I have two data sets. The first data set has approx. 50.000 movie and song titles and the second one have 20.000 blacklist strings. I am looking for the best algorithm to detect movie/song title which ...
  • 336
-2 votes
1 answer
104 views

Finding the domain(s) of variables in a Linear Program using the constraints? (Constraint programming/Linear programming)

Forgive my jargon , as I'm not very familiar with Constraint Satisfaction Problem(s) or Linear Programming procedures (For eg: Presolve) I have very trivial constraint set from variables of ...
2 votes
1 answer
355 views

Efficient and fair way to evenly distribute multiple items with various quantities

I am developing small lottery games where the participant can win one of many gifts, each having various quantities. (The code is in PHP) Simple scenario: I have 5 types of gifts, 1000 in total, and ...
2 votes
3 answers
341 views

How to clone an object graph and keep relationships of objects intact?

In my ASP.net core application with Angular 2+ client, I work with a complicated object graph. In the object graph I have some objects with references to each other. I have a simplification included ...
1 vote
1 answer
49 views

Finding Event-Oriented Patterns in temporal sequence

I have a 24 hour "sliding window" sequence of "start" and "stop" events in memory comming from an iOT device. I'm only interrested in finding "stop" events followed by "start" events in order to ...
3 votes
1 answer
131 views

Synchronizing video playback in LAN over UDP (no master, same HW & SW)

I have devices thay play video files from their local disk basing on a pre-defined playlist (every device plays exactly the same movie in the same order, every device knows in advance what videos will ...
3 votes
1 answer
109 views

Algorithm for fulfilling an order using pre-packaged goods

A manufacturer sells different flavour chocolates. Customers can place an order for any number of each flavour chocolate, from zero upwards. Some combinations of chocolates are frequently ordered, ...

1 2
3
4 5
44