algorithm

• Complexity when generating all combinations2019-03-17

Interview questions where I start with "this might be solved by generating all possible combinations for the array elements" are usually meant to let me find something better. Anyway I would like to add "I would definitely prefer another so

• Getting Wrong Answer in "Longest non regular parentheses sub-sequence "codechef june cook off2019-02-19

I attended a programming competition(it has ended now). I don't know why my solution is giving WA, I read the editorial, saw other people solution but unable to find a flaw in my solution. Obviously I am missing somewhere. Please help! Question Link

Tags: algorithm
• Why are my nested for loops taking so long to compute?2018-07-18

I have a code that generates all of the possible combinations of 4 integers between 0 and 36. This will be 37^4 numbers = 1874161. My code is written in MATLAB: i=0; for a = 0:36 for b= 0:36 for c = 0:36 for d = 0:36 i=i+1; combination(i,:) = [a,b,c,

Tags: algorithm, big o, matlab, time, nested loops
• I need to group addresses given their distances. Let's say I have a list of 8 addresses. 5 in NYC and 3 in New Jersey. From those 5 in NYC 3 are close to the MET and 2 to the WTC. Those 3 in NJ would form one group, those close to the MET another and

• How to find if two or more texts are correlated2018-05-06

Say we have two english texts T1 and T2 (disjoint no overlap ) cut out from a larger text T. Is there a way to figure out that T1 and T2 came from a single larger text? For example , newspaper layout is in multi column text. Given two column of text

Tags: algorithm, nlp
• How can I iterate through all possible grid layouts?2018-03-10

I have a grid (an NSArray of CGPoints)where I want to layout some objects at points based on some constraints. This is what I know: How big the grid is The number of objects that have to be laid out on the grid, at a point The minimum distance betwee

Tags: algorithm, combinatorics
• Peg Solitare Recusion solution2018-02-13

Everyone knows of the cracker barrel triangle peg solitare game. You take one peg and jump it over another into an empty hole and the goal is to have only one peg left. In my code for the game board object I have a function sCpeg(int a, int b) which

Tags: algorithm, search, recursion
• what is algorithm to undirected connected graph to biconnected graph by adding edges?2018-01-22

I have a non directed graph that is connected. I want to make it bi-connected by adding minimum number of edges. How can i do it? I tried searching online for this particular algorithm and also tried thinking myself without success. Please help me un

Tags: algorithm
• Is it possible to implement A* path finding with a set of objects containing 4 or more vertices each?2018-01-22

I have a set of objects (rectangles having 4 vertices of (X,Y) each) draw on a map using OpenGL ES. I would want to implement way finding between each of them. For example I have rectangles A,B,C,D,E Structure: A[Vertex(X,Y),Vertex(X,Y),Vertex(X,Y),V

• Implementing a randomly generated maze using Prim's Algorithm2018-01-14

I am trying to implement a randomly generated maze using Prim's algorithm. I want my maze to look like this: however the mazes that I am generating from my program look like this: I'm currently stuck on correctly implementing the steps highlighted in

• How to maximize the number of elements per btree node2017-10-27

I am constructing a btree from some data. Once I construct the btree (i.e. insert all the elements) I no longer insert or remove elements. However the resulting btree is not optimal in a sense that if I can have n maximum elements per node very frequ

Tags: algorithm, b tree
• Proving optimality of greedy algorithm2017-09-27

Problem I came across is as follows: We have n tasks with l_i and w_i being completion time and weight of task i. Come up with an algorithm that minimizes sum for all i of f_i * w_i where f_i is time when task i was finished. If for example some task

Tags: algorithm, pseudocode, greedy, proof
• What algorithm is this? Best way to distribute limited resources2017-07-29

I recently saw this question on a programming challenge, and I'd like to know which well-known CS algorithm this resembles. I implemented a crude solution. I know there must be a better way to do it, but I'm not sure of the terms to search for. It se

• How to cluster large datasets2016-10-25

I have a very large dataset (500 Million) of documents and want to cluster all documents according to their content. What would be the best way to approach this? I tried using k-means but it does not seem suitable because it needs all documents at on

• For a given graph G = (V,E) how can you sort its adjacency list representation in O(E+V) time?2016-07-23

Because we know that the integers representing a vertex can take values in [0,...,|V|-1] range, we can use counting sort in order to sort each entry of the adjacency list in O(V) time. Since we have V lists to sort, that would give us a O(V^2) time a

Tags: algorithm, graph, sorting
• Multi-way KK differencing algorithm vs. Greedy algorithm?2015-12-06

It's proven that, the Karmarkar-Karp's differencing algorithm always performs better than greedy for 2-way partitioning problems, i.e. partitioning set of n integers to 2 subsets with equal sums. Can this be extended to k-way partitioning as well? If

• Path planning algorithm for connected multi-robot system2015-08-19

Say I have three robots connected as a triangle, how do I manage to avoid obstacles in working space? I'm thinking about using A*, but I got problem that it works for one robots but when comes to 3 robots it will cause collision. I'm really new to ro

• Recommendation system with big un-tagged data set2015-03-10

Suppose, there is an e-commerce site with at least a million products falling in different categories, but no tags or categories are specified. The only information available on each products are the title string of the product, an image and a descri

• Check If there exists a Circle2015-03-10

I was asked this during a Google Interview. We are given a string consisting of letters- F,L,R. - which is the instruction a robot follows F- goes forward by one step. L-turn left. R- turn right. String length can be upto 2500 characters. The string

• Are there sorting algorithms that respect final position restrictions and run in O(n log n) time?2015-03-03

I'm looking for a sorting algorithm that honors a min and max range for each element1. The problem domain is a recommendations engine that combines a set of business rules (the restrictions) with a recommendation score (the value). If we have a recom

Tags: algorithm, big o, sorting