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
1answer
120 views

Is my reasoning to determine this algorithm's Big-O correct?

Take the following algorithm with two separate sections, and the sections do not influence each other whatsoever (the function is not recursive, as well). void algorithm(int x) { // This section ...
2
votes
2answers
207 views

Algorithm for splitting players into unique group every round

For a match I have certain number of players, certain number of groups (players and groups are aliquot) and certain number of rounds to be played (players are reshuffled every round). Ideally, I'd ...
1
vote
1answer
107 views

Scheduling Rules and Complexity in Coding Lots of rules respect to time?

We have some fields (age, visit type, insurance type, city) and some rules: Some doctors that define weekly schedule template like as: Doctor D1 works on Monday 7-9 pm , Thursday 7-9 pm. Some type ...
7
votes
2answers
549 views

FIFO Min-Max-Heap for Rolling Median

I'm working on a system with hard real-time constraints in c++ and I need a very fast way to calculate the rolling/moving/streaming median of a set of numbers of size N=100 to 300. Normally this size ...
2
votes
1answer
127 views

Calendar scheduling: wait time between games

I am working on a sports scheduling algorithm with several different constraints, one (two) of them being a minimum and/or maximum wait time between games. Of the same team, that is. So if Team Blue ...
0
votes
1answer
665 views

Reverse engineering a checksum or CRC

I am trying to reverse engineer a checksum or CRC wherein an 8 bit number* gets converted to a 5 bit number for error checking. I have an incomplete list of data values and checksums, and need to ...
2
votes
2answers
4k views

How exactly indexing works in arrays?

I only know that index is faster but don't know why is it faster. Suppose I have an array int[] a = {2,3,6,7}. Then I will try to find the element at a[3] and the speed of this will be O(1). Why? How ...
6
votes
1answer
781 views

Fastest way to find N closest vectors to vector X in list?

I have a bunch (~20,000) of large (~200 dimensions) vectors in an unsorted list. I can create a new vector of the same size, and I'd like to find the top N (usually 10 or so) closest (defined by ...
1
vote
1answer
106 views

What is the most efficient way to represent resizable adjacecny matrix

I'm building a simple app that represents some matrix, where nodes are added quite often. Currently I have following code for adding a new node: let mut new_edges = Array2::default((position + 1, ...
-1
votes
1answer
1k views

Generating billions of Unique random number [closed]

I recently attended an interview. In that I had to solve the issue for generating an billions of random unique number. For example method signature is as below : public Iterator<Long> ...
3
votes
1answer
69 views

Architect Solution to generate set of Default Phrases from a large list of specific phrases

We have a large set of existing key-value pairs (e.g. product specs). A made-up example might be: Prod 1, LOGO, The standard 1990 Audi logo is located in the center of the grille. Prod 2, LOGO, The ...
1
vote
1answer
129 views

How to scale a file based process

I'm looking for a method to solve the following problem: Assume there is a spool directory with a lot of files that need to be processed. There is a process A that is constantly writing new files to ...
5
votes
2answers
381 views

Grouping objects according to a set of fields

I would like to sort a list of people into buckets, as duplicates, by an email comparison, but I can't seem to find an efficient way. Specifications A person has 5 email fields, so in order to know ...
-2
votes
1answer
183 views

a valid ranking algorithm for facebook posts

I'm creating a website which will collect posts from facebook's pages to show to the users posts they are interested in (as my graduating project). I'd like to be able to rank the posts that contain ...
4
votes
3answers
2k views

In merge sort, why not just split to individual items immediately rather than recursively splitting in half?

In learning the merge sort, the examples show the list of items being split in half over and over again and then merged again. Why not just start with iterating over the individual item pairs in the ...
1
vote
1answer
70 views

Efficiently determining available options based on prior selections

I'm looking for a known design pattern or algorithm that can be used to effectively determine a set of available options to be presented to a user based on previous decisions. An extremely simple ...
-2
votes
2answers
7k views

Algorithm for scheduling shifts

I am trying to write a program to help scheduling shifts for the employees of a small business. There are 28 shifts that needs to be assigned to 28 employees (so this means that each person gets a ...
3
votes
2answers
4k views

SQL algorithm for most overlapping events

The Problem I'm looking for a query to help me solve the following: I have a series of events Each event has a start and end date. Many of these events overlap The answer I'm looking for is the ...
7
votes
3answers
574 views

System Design: Very Large CSV Imports Every Month

We have a webapp that will rely on large CSVs from external vendors every month. When I say large, we are looking at around 6gb so a few million rows. Probably, 2-5 CSVs. This webapp will also allow ...
1
vote
2answers
131 views

Determining resource exhaustion beforehand

I guess this is a problem solving question but I am out of ideas, don't really know where else I can resort for help, and I need to solve this problem. Essentially we have a set of consumers and a ...
3
votes
5answers
1k views

Fastest way to find all numbers with digits

I have a huge set of over a million numbers of variable lengths. ['773', '2267', '8957251', '170597519', '373590109', '982451707', '999999937', ......] Now given a bunch of digits, say 3 and 7, I ...
3
votes
0answers
149 views

How do large scale permission systems work with membership expansion?

Let's say you have a permission system with which you can specify things like: user U is a member of group A, which is a subgroup of group B, which is a subgroup of group C, and all members of group C ...
-3
votes
1answer
72 views

Identify sets differing by one

I have a set of objects with different attributes; e.g. a set of cars with colors, brand etc. I choose subsets by virtue of a specific set of attributes. Now I want to identify pairs of such subsets ...
1
vote
1answer
45 views

Algorithm: Identify same Outlets / Supermarkets

We have a database with stores Outlets / Supermarkets (mainly in germany but other countries are also possible). We store some informations of this outlets / supermarkets like name, street, ...
2
votes
2answers
150 views

Receive data in random order, send in order

I am facing an issue where I have a data stream that sends unordered data. I'm trying to find a way to receive the data in random order, but send it in order. As an example, I'll receive object4 and ...
5
votes
3answers
537 views

How to implement the travelling salesman algorithm with dependecies between locations

Is there a way to implement the traveling salesman or purchaser algorithm with constraints between locations? For example, I have to grab item X before item B, c before D and F,G,H in any order.
2
votes
1answer
2k views

Algorithm for a round robin based tournament with a specific amount of matches per round

I'm currently trying to create a system for a specific tournament but I can't figure out how to generate the matches table. I have a tournament with <T> teams. Each team needs to play vs each ...
6
votes
1answer
5k views

How are queues made thread-safe in Python

I admit this was asked to me in interview a long time ago, but I never bothered to check it. The question was simple, how does Python make Queue thread-safe? My answer was, because of Interpreter ...
2
votes
3answers
217 views

Find the least words that will use all given letters

With a list of thousands of words and a small list of letters I am trying to find the least amount of words to make use of all given letters, assuming my dictionary of words covers all letters. The ...
5
votes
3answers
309 views

Can referential transparency be assumed when dealing with floating-point arithmetic?

A pure function is assumed to produce the same outputs given the same inputs. Suppose an (otherwise) side-effects free function computes with floating-point numbers. Due to numerical error, these ...
0
votes
1answer
207 views

Binary Tree and Variable Length Codes for given Alphabets using Huffman Encoding (Confusion)

Last week our teacher gave us a question about Huffman Encoding Algorithm described as below. HUFFMAN ENCODING ALGORITHM: Consider all pairs: . Choose the two lowest frequencies, and make them ...
-1
votes
2answers
645 views

How to list the compound words from a dictionary [closed]

For Example my input is this dictionary s=["noon", "n", "o", "noo", "Good", "Goodnoon", "marry", "me", "marryme", "air", "r", "airbag"]. The output should be a list of compound words. like Good noon, ...
6
votes
3answers
3k views

Effecient algorithm for data deduplication in procedural code

I have written a data cleansing application which, for the most part, works well. It is not designed to handle large volumes of data: nothing more than about half a million rows. So early on in the ...
-2
votes
1answer
61 views

What is the best approach to find elements in collection that fullfill scenario

I have a collection of people. Each person have rank (A, B, C, D where A highest and D lowest) and set of skills (SkillA, SkillB, SkillC, SkillD) defined. I also have a set of requirements - for ...
1
vote
2answers
151 views

How to dynamically weight a random generator to guide a result set toward a desired distribution? [closed]

Say I have a function that returns a weighted selection from a set of resources, according to a desired distribution. For argument's sake let that resource be string colors. const distribution = { ...
-2
votes
1answer
34 views

Finding 3 equally spaced boolean cells

Given an array A[N] of N booleans, return a, b such that a >= 0, b > 0 and A[a] = true A[a+b] = true A[a+2b] = true or -1 if they don't exist. The best algorithm I could find was brute forcing ...
2
votes
1answer
303 views

Am I allowed to simplify terms while calculating Big O?

I want to calculate the runtime of the following function T(n) = (1+2+3+4+5+...+n)/n At first this doesnt seemed hard to me because it can be solved easily by transforming the formula T(n) = (n(n-1)...
1
vote
1answer
612 views

How do I interpret this postfix right-to-left algorithm?

I'm trying to implement this right-to-left evaluation algorithm of a postfix expression but I can't seem to get it to work. for each token in the reversed postfix expression: if token is an ...
0
votes
1answer
652 views

Computing the shortest path in a labyrinth

I'm currently trying to map how to make a good algorithm that won't have issues to find the shortest path. The labyrinth consists of an X and Y dimensions as input; However, the labyrinth will ...
2
votes
2answers
177 views

Algorithm to select sets of objects while maximizing number of objects covered

If we have different objects, [A1, A2, A3, B1, B2, B3, B4, B5] Some calculations will be performed to find compatible objects. For example, lets assume following 3 sets were formed and every set ...
2
votes
1answer
411 views

What data structure is this?

Imagine I have a set of houses I want to sell and I want to present then on a website. The user should be able to filter the house they want by price, city, number of floors, area etc. However, I don'...
-1
votes
2answers
149 views

Describe a slope (N/M), approximately as small number of fractions (n/m)

What algorithm can I use to describe a specified gradient (N/M) approximately as the sum of a set of rational fractions { (n1/m1) + (n2/m2) … } ? Design constraints: The algorithm takes as input (N, ...
0
votes
2answers
140 views

Trigger no more than M events per second, simulate N increments per second

What algorithm should I use, to simulate a continual stream of N increments each second — not writing a loop, but instead by timed-interval events, no more than M events per second? I am implementing ...
2
votes
1answer
254 views

Algorithm to determine direction based on previous tiles

Let’s say I have an object, called “Tile”, which has both a name and a list of directions. We’ll assume that each tile has a 3x3 grid of pixels, which can either be on or off. The middle center pixel (...
5
votes
1answer
1k views

Algorithm for assigning people to time slots based on preference

I'm attempting to figure out if an algorithm currently exists to accomplish what I'm trying to accomplish. I have a series of time slots over the course of a week where I wish to assign a roughly ...
5
votes
1answer
2k views

Split overlapping ranges into all unique ranges

I am trying to split a dynamic number of ranges with associated attributes, so that whenever 2 or more ranges overlap, the overlapping section(s) are split into unique ranges with the combination of ...
-1
votes
3answers
303 views

Algorithm for Uneven Product allocation in Multiple Warehouses with PHP

I have a script which returns the ID's of the warehouses (4,1,2,10,9) in order how close they are to the customer. $warehouse_rank = array('0'=>4,'1'=>1, '2'=>2, '3'=>10, '4'=>9); ...
0
votes
8answers
880 views

Win/lose algorithm

I'm trying to figure out a win/lose algorithm where we have to have (around) X winners per day spread across the day without knowing the number of participations. A user sends a request to an ...
5
votes
2answers
345 views

What are efficient algorithms for immutable dictionaries/sets? [closed]

What are efficient algorithms for immutable dictionaries/sets? By efficient I mean they either have better or comparable time and/or memory performance compared to their mutable versions. I don't ...
3
votes
3answers
340 views

What strategy should I follow to draw a forest of trees represented by an array

I have an array of integers representing connectivity of nodes.Consider the following states of the array after each time it's changed: 0|1|2|3|4|5|6|7|8|9 => Root of each node is itself 0|1|2|3|3|5|...

1
3 4
5
6 7
42