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)

0
votes
0answers
32 views

Using binary search in different scenarios

I have to give my one of the biggest interviews next week and I am working hard for that. I have also enrolled myself for some mock interviews for that. So, coming to the problem last day I had this ...
0
votes
1answer
43 views

How do I write an algorithm to solve a set of 3 symbolic equations

Replace each symbol (letter) with a number so that the equations hold across all 3 equations. Solution should be able to solve the general case of any 3 equations. Can assume 2 terms summed to an ...
-1
votes
0answers
22 views

Finding number of pairs of nodes in a tree having specific XOR

I was trying to solve the Monk and Xor Tree question on HackerEarth, where each node has a specific xor value and we want to find number of pairs of nodes whose xor of the path of the nodes is 'k'. ...
-1
votes
0answers
22 views

Worker Distribution Problem

I've a code for checking game implementation. I get a buildlist as an input. Think of the game like AoE. There are 2 types of minerals (eg. gold, wood). I've worker who can either mine the minerals or ...
-1
votes
1answer
24 views

Need Help to build a Custom Notification read logic for Individual user basis

I'm building a custom Notification section, which provides notification or messages to multiple users on any particular object update, I've created a HTML page like Dashboard where I have added a ...
4
votes
4answers
132 views

Algorithm for optimal trades along a fixed route

Imagine you are in charge of a cargo ship: travelling along a fixed route or loop (A, B, C, D, A...) has a maximum cargo capacity At each stop you can: buy commodities, up to your cargo capacity, ...
3
votes
1answer
48 views

Find k max integers of an array — Min Heap vs. Selection Algo vs. Selection Sort

I have an array with a large number of elements, and I need to find the k largest elements. For an idea of scale, let us assume an integer array of length 10,000,000, and k is 1,000. I see three ...
-1
votes
1answer
53 views

How would an algorithm that creates a 360º image out of photos work [closed]

I had an idea. These are the steps that it involves: Take n photos that together provide a 360º view about a point/area Construct a texture for the inside of a sphere out of these overlapping images ...
3
votes
1answer
99 views

C++ generic graph search algorithm with generic data types

I'm trying to implement a generic graph search algorithm in C++, as part of assignment at university, and I encountered problems when trying to implement it, mostly struggling with templates. this is ...
-1
votes
0answers
41 views

Algorithm for a matter of chance game

I started developing an algorithm for a matter of chance game with the following rules: At the start of the game, the player starts on the starting case S(Start). He starts by rolling the dice and ...
1
vote
2answers
116 views

How to detect thin extrusions from a polygon?

I want to create a minimal polygon which approximates the boundary of an arbitrary (semi-random) shape. By "minimal" I mean, "as few points as possible". The original shape (to be bounded) is in ...
-2
votes
1answer
67 views

Monte Carlo Tree Search for TicTacToe doesn't block opponent's winning moves

I've made a program to play TicTacToe against a human using a Monte Carlo Tree Search (MCTS) with UCB1 for node selection. The program will play moves until it wins but it will not make any attempts ...
0
votes
0answers
34 views

When implementing Monte Carlo Tree Search for TicTacToe, do I simulate won states?

I'm trying to debug my MCTS implementation for TicTacToe (it doesn't block obvious wins for the opponent). I was wondering what the algorithm should do if it expands to a node which is a game over ...
2
votes
0answers
87 views

Algorithm to find region with least-probable density

Consider the following boolean array where dark == true: In this scenario the probability that a cell is dark or light is 50/50, but this may not be true for the general case. Maximizing only on ...
3
votes
1answer
63 views

Algorithm for windowed online covariance

I'm trying to adapt an algorithm to calculate covariance to work over a rolling window on the data. Wikipedia has an algorithm for online covariance: def online_covariance(data1, data2): mean1 = ...
2
votes
3answers
282 views

Is the Time complexity of this function o(n) ? Can it be optimized any further?

This is a very simple function to find if a string is composed of unique characters. I believe that this is a O(n) time complexity as it loops once and has a single if condition. Am I correct? Is ...
1
vote
1answer
85 views

Finding the minimum transaction

Given a list of transactions like: A -> 10 to B B -> 10 to C The naive way to settle the transaction would be: C owes 10 to B B owes 10 to A But the same transaction could be settled by: C ...
4
votes
1answer
116 views

Calculating averages of rows in a very large dataset

We have a ratings system in our website that allows users to provide feedback to 3 different questions about a user. We currently calculate the rating using averages using the following query on our ...
0
votes
1answer
35 views

Data structures and algorithms for event correlation

What data structures and algorithms are suitable for event stream correlation? Specifically, I am looking at these two use cases: X occurrences within t seconds grouped by some variables (v1,v2). For ...
6
votes
1answer
126 views

Algorithms for color blending modes: hue, saturation, color, luminosity

I'm working on a JavaScript utility where I'm trying mix two colors in different ways. I basically want to cover the blend modes provided by Photoshop / the W3C spec on compositing and blending (which ...
3
votes
1answer
130 views

Algorithms comparison and complexity

I want to sole this problem: Write a method to return all valid combinations of n-pairs of parentheses. The method should return an ArrayList of strings, in which each string represents a ...
1
vote
2answers
139 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;...
6
votes
2answers
202 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 ...
2
votes
0answers
179 views

Design elevator system algorithm and classes? [closed]

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 ...
2
votes
0answers
45 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
70 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 ...
0
votes
1answer
51 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
56 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 ...
1
vote
0answers
42 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
67 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
62 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
174 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
vote
4answers
160 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
103 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
91 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
221 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
88 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
68 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 ...
6
votes
3answers
224 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
90 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
136 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
69 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
52 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
66 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
138 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
124 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 ...
3
votes
3answers
78 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
79 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
92 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 ...