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.

learn more… | top users | synonyms (1)

1
vote
1answer
67 views

Decimal to Binary Explanation

string convertDigitsToBinary(int n) { string ans; if (n == 0) return "0"; while (n > 0) { int rem = n % 2; ans.push_back((char)('0' + rem)); n /= 2;...
-7
votes
0answers
31 views

Binary search algorithm to solve this problem [on hold]

I was assigned this problem i have to solve: There are plenty of guided activities in a certain swimming pool. Therefore, the usage rules are very strict: The free time slots are only one minute ...
5
votes
1answer
107 views

Is a random sample from a range of uniformly distributed values still uniformly distributed?

Let's say I have a random number generator from which I am requesting values for event A and event B. Both events occur at random intervals but event A happens much more often than event B and I would ...
-6
votes
1answer
35 views

How to program a Intelligent agent to understand chemistry [on hold]

I was wondering if anyone could help me with this particular question, I'm working on making a intelligent agent to understand chemistry, the intelligent agent I'm using is a Utility Based Agent and I'...
1
vote
0answers
137 views

Design elevator system algorithm and classes? [on hold]

Here are the main classes I can think off the top of my head. All business objects will follow the abstraction (implement interfaces). I have not mentioned interface names to avoid verbosity. I have ...
1
vote
0answers
39 views

What's the most practically efficient way to store differences in adjacent matrix values?

I am implementing a certain algorithm that works like this: Create a closed contour (list) of elements in a matrix, where closed means that the last element is adjacent (by row, column) to the first. ...
0
votes
3answers
66 views

What are some strategies for understanding algorithm variables semantics?

I'm reading the book Clean Code by Uncle Bob. I'm also enrolled in a data structures & performance course and reading several algorithms and data structures books. One immediately apparent ...
-1
votes
1answer
77 views

Share the ride among car owners and passengers [closed]

The question is about car pooling. There are n number of car owners and n number of passengers who wants to share a ride with car owners. Let car owners be c1,c2,c3,.......cn. and passengers be p1,...
0
votes
1answer
44 views

Aligning text columns of different size and content

In a past posting, I asked about commands in Bash to align text columns against one another by row. It has become clear to me that the desired task (i.e., aligning text columns of different size and ...
0
votes
2answers
54 views

What is total order and how can generate and maintain total order among the proposer proposals in paxos?

1) What is total order? Does total order mean the consecutive numbers must be strictly less than "<" or it can less than or equal to "<="? 2) how can generate and maintain total order among the ...
0
votes
0answers
17 views

Minimum cost perfect matching (Using General graph)

This is a continuation of the problem described in this topic: Optimized algorithm to match entities together based on heuristics. I've come a little closer as to what might be the best solution. I'...
0
votes
1answer
65 views

Efficient algorithm for finding the breaking point between two entries

I've got an API endpoint which looks like this: http://foo.bar/rest-method/{identifier}. This API returns an object that looks like that: { name: "Example", version: "1.0.5.3937" } Now I ...
1
vote
1answer
58 views

Optimized algorithm to match entities together based on heuristics

I've encountered a problem which I think is rather suited to be solved using a Constraint Satisfaction Problem algorithm. I am however, not entirely certain that this is the best approach, as the ...
5
votes
1answer
168 views

How do parsers search for token patterns?

Could you explain how parsers search for token patterns like in markdown? I probably could come up with something matching only the braces pattern []() as soon as nested patterns are involved it ...
-1
votes
0answers
30 views

Algorithm for finding the number of occurrences of all shared substrings strings between 2 strings regardless of starting index?

I've run into an unusual challenge and so far I'm unable to determine the most efficient algorithm to attack this. Given the following 2 strings as an example, find all commonly shared substrings ...
1
vote
4answers
155 views

Comparing objects with tolerance

The following code says that c1 == c2 and c2 == c3, but c1 != c3. TOL = 0.11 class C: def __init__(self, x): self.x = x def __eq__(self, other): return abs(self.x - other.x) ...
0
votes
0answers
101 views

Is my persistent storage strategy efficient for my project's objectives?

I am trying to build a key-value store (to learn, I am a student) that would serve as a persistence layer for software applications. I have looked into the database literature and dived a little bit ...
0
votes
1answer
88 views

Algorithm for efficient scale down of 2d boolean array

I have a 2D boolean array for example: 01000000 01110000 00110000 01100000 00100000 00111100 00000000 00000000 What I want is to efficiently create a scaled representation for this array according ...
3
votes
1answer
219 views

Is a trace table useful in functional programming?

A trace table is a technique used to test algorithms. "The table usually takes the form of a multi-column, multi-row table; With each column showing a variable, and each row showing each number ...
0
votes
1answer
82 views

Two-center algorithm to find minimum of farthest point

I'm trying to come up with an algorithm that allows me to find two vertices in an undirected, weighted graph that minimizes the distance to the farthest point. Distance of the farthest point is ...
-2
votes
2answers
64 views

Shortest path common core(s) question

I'm not sure whether I'm using the correct terminology here. I'm trying to come up with an algorithm that let's me find a vertex in an arbitrary graph so that the vertex has minimum distance to the ...
5
votes
3answers
216 views

How would you go about making a search algorithm for a CRM?

I know this question is kind of broad, but all I really need is some best-practice code structure or a link to a good tutorial. I am working on a CRM that runs on php and mysql. Currently, our search ...
3
votes
1answer
83 views

Algorithm to check for legal moves in Cluedo boardgame

I'm making a Clue(do) board game in Java to improve my programming skills. I've done a lot of work so far, but now I'm stuck at finding an algorithm to make sure if a player can make a certain move. ...
0
votes
2answers
131 views

What programming techniques are there to find the combination of inputs that produces the best result? [closed]

I am working with a big set of data right now and I wrote a program that calculates a result based on some inputs. I have 10 inputs, each of them has about 20 different possible values. I am not sure ...
-2
votes
1answer
67 views

Given huge list of sub sets, on receiving some super set find best match sub set

Given finder : List of map, key : String, Val : String. On receiving super map : a map which is super set of one or more map in a finder, find map from finder list which has contains maximum ...
1
vote
1answer
51 views

Is it possible to make this grouped permutation algorithm more efficient?

The following program starts with hundreds of permutations and shrinks them down to a small result set. Furthermore, I am only looking for the first valid result. What techniques can I use to make ...
0
votes
2answers
51 views

Algorithm for searching a domain name in list of wildcard

I have a list of domain name that contains wildcard ('*' character) Example: *.google.com *.domain.com ... It contains nearly 1 million domains. The data will be stored on a mongodb or redis ...
0
votes
1answer
101 views

Why the search time for TreeSet is O(nlogn)?

In my naive opinion it should be O(n) in worst case since Tree could get spindly and unbalanced.
0
votes
1answer
105 views

How to solve this algorithmic problem? Is there a polynomial exact algorithm?

The problem goes like this: There are n piles of wooden planks and m machines, let xi be the number of planks in i-th pile. The machines produce different parts for chairs; each machine requires a ...
-4
votes
1answer
123 views

What's the best algorithm to assign unique ID/serial numbers to a group of identical objects?

to make this question easier to visualize, let's call this the "chicken mesh problem". Suppose you have a rooster and a number (suppose it is 30) of baby chickens. Goal: Allow the rooster to ...
0
votes
0answers
26 views

Implementing my own Integer.toBinaryString(int n) method [migrated]

Our senior developer gave us (trainees/jr. developers) a small exercise and that is to make our own Integer.toBinaryString(int n) implementation. This is the answer I came up with. I would just like ...
3
votes
3answers
75 views

Say we have a group of N person, and each person might want to sell or buy one of the M items, how to find a closed path among them for an exchange?

Say we have N persons and M items (when a person has a certain item, she usually only has one piece). For example, person 1 has item A, C, D, and wants item F person 2 has item B, C, and wants E ...
1
vote
1answer
78 views

Get Unique random numbers within predefined limits

I am looking for an efficient algorithm to get unique (non repeated) x amount of integer random numbers that are within the y and z limits. e.g. I want x random integer numbers that are bigger or ...
1
vote
1answer
88 views

Majority voting algorithm, there are n people and m candidates but m is known

The question is long, so I will paraphrase it briefly Q: There are n people voting to choose the chair of the committee. Each person can vote for one person that has unique id (it is positive integer ...
1
vote
0answers
22 views

Check if a point is deviating from a path made by a set of line segments

I'd like to know or have other ideas --other than my solution-- about how to check if a car on a given position (lat, lng) is getting away (let's say a distance D away) from the path where the car ...
0
votes
1answer
69 views

Why isn't this combinatorial solution equivalent to the recursive solution for finding the number of “paths”?

Here's the problem: Given an m x n array, get the number of different paths from the top left corner to the bottom right corner, if you can only move down, right, and diagonally down & right. ...
9
votes
3answers
242 views

Picking the most calorie-even arrangement of meals

Suppose I eat five meals a day, and since there are seven days in a week, I have recipes for seven of each meal, for 35 recipes in total. Each recipe has a calorie count. Each day must contain one ...
22
votes
8answers
2k views

You are given a file which contains all possible numbers on a 32-bit architecture. 4 numbers are missing from that file. Find the 4 missing numbers

This is an interview question that I've run across a few times, and I'm really not sure how to solve it given that four numbers are missing. I'm familiar with algorithms for finding one or two numbers ...
-1
votes
2answers
78 views

What programming environments can be used to illustrate and benchmark the unoptimized space complexity of an algorithm?

What programming language along with implementation and compiler can I use to study the pure, unoptimized space complexity of an arbitrary algorithm? And what methods can I use to do so? For example,...
0
votes
1answer
24 views

Validating combinations based on rule sets (or similar mechanism)

Let's say I've got many functions and each function accepts an unordered list (order does not matter). For each function I want to see if this list is valid based on certain rules (a knowledgebase ...
2
votes
1answer
187 views

What is this Algorithm called? [Traveling Salesman Problem]

I've been thinking about the Traveling Salesman Problem. In examining it and grids of cities, I noticed that I could frequently pick out the shortest route just by staring at it. Granted, I couldn't ...
4
votes
1answer
176 views

Implementing the Cashier's Algorithm in a vending machine

This code golf question got me thinking. I wasn't even aware that the Cashier's Algorithm was a formal thing. Reading it, and Googling around, I see that all solutions seem to concern themselves ...
5
votes
2answers
121 views

Efficiently consuming a rate-limited service

So my exact case is that I have ~1400 domains on an ancient, self-hosted bind server and I'm looking to migrate them to a hosted service. The trouble is that the hosted service's API has a rate limit ...
2
votes
1answer
85 views

Future data integrity (n years)

So recently, I had a client ask me to restructure his Database hierarchy which consisted mainly of changing table names and column names and creating cross-references to stop red locks. He later ...
6
votes
5answers
446 views

Splitting integer so that both sides are prime numbers

The problem You're given an n number. Check if that n number can be splitted in half so that both sides of a | are prime numbers. Example: Input Output 223 2|23 123 Not possible to split. My ...
3
votes
1answer
314 views

Why are pure functions easier to reason about?

In computer programming (I code in c#), why are pure functions easier to reason about? From my own experience, I find that pure functions are easier to reason about because they lack side effects, ...
1
vote
0answers
95 views

Sorting Lower Bound in the Comparison Model (Nuts & Bolts Problem)

Problem: Assume that we are given n bolts and n nuts of different sizes, where each bolt exactly matches one nut. Our goal is to find the matching nut for each bolt. The nuts and bolts are too similar ...
0
votes
1answer
62 views

how to reach all nodes in a Tree Structure where end of the tree is unknown

There is a XML link, which provides the children of any parentID given. http://www.browsenodes.com/xml.php?action=BrowseNodeInfo&node=1036592 Then you can run the URL again with a children ID ...
2
votes
2answers
120 views

Small Search Engine Algorithm for Document Word Search

I have to design and implement an algorithm for my university project that searches a given set of documents based on the keywords/query given. Assume that each document contain few sentences and ...
0
votes
3answers
228 views

Mental model for working with linked list [closed]

I have been doing some practice problems on LinkedList but more than half of my time is spent on managing null pointer issue in my code, provided I have to keep track of current, previous and runners ...