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.
5
votes
5answers
206 views
What sort of questions drive the decision as to whether similar code is separate or common?
I have come across the following problem many times in various guises in my programming career. As a simple example, consider the following:
Let's say there is a method (B) that could differ ...
1
vote
1answer
177 views
Need help understanding Dice Game question [closed]
I am stuck at a question preparing for a gaming firm, and my problem is that I don't understand the game that is presented.
Create a dice game in which there are two players and three 6-sided dice ...
7
votes
1answer
206 views
Longest subsequence without string
Does there exist a dynamic programming algorithm to find the longest subsequence in a string X that does not contain Y as substring? Just that this problem seems so similar to other DP string ...
-4
votes
1answer
80 views
Generate all possible combinations of N elements from a set of M elements [closed]
Given a set of M elements, which could be an array of size M containing some objects, I need to generate all possible subsets (with repetitions) of size N. Is there any C++ library with this ...
1
vote
1answer
80 views
LOOP program only need inc and zero
I have 4 different commands in LOOP programming language:
y=Zero()
y=Val(x)=copy x and put it in register y
y=Inc(x)=x+1
y=Dec(x)=x-1
Finally I also have
loop n times {
...
...
2
votes
1answer
115 views
LOOP-computable functions
I was just reading a chapter about LOOP-computable functions and I have the following question: Is it possible to numerate every LOOP program with an algorithm?
Formally: Is it possible to have a ...
13
votes
3answers
246 views
Visiting points on a number line while minimizing a cost not related to distance
I need some help on this ACM ICPC problem. My current idea is to model this as a shortest path problem, which is described under the problem statement.
Problem
There are N = 1000 nuclear waste ...
0
votes
0answers
25 views
Minimizing the emitted radiation - number line [duplicate]
Here's another programming puzzle that I'm doing in preparation for competitions. Again, I'll outline an abridged version of the text and then talk about what I've thought of so far.
Problem
There ...
1
vote
0answers
44 views
How to compute amoritized cost for a dynamic array?
I am trying to understand how to do the amortized cost for a dynamic table. Suppose we are using the accounting method.
Let A of size m be an array of n elements. When n = m, then we create a new ...
-1
votes
0answers
135 views
I feel like I've hit a dead end [closed]
I've been doing programming as a hobby for several years, originally starting back in high school with game development and now doing primarily Web development. I've worked on numerous side projects ...
3
votes
1answer
209 views
Convert letters to numbers
I have the following problem.
Given A=1, B=2 , ... , Z =26
I need an algorithm that given a letter combination, like the column order in excel, returns me the number/
AA=27
AB=28
ABC?
Thanks a ...
5
votes
2answers
214 views
What could an algorithm look like that iterates through all combinations of two variables to aim at a certain number of entries?
For background information, see "Some background" further down.
I have a list that looks like this:
Start-Time-In-Seconds;End-Time-In-Seconds
1;2
4;6
12;15
...
This works together with a wave file ...
-1
votes
1answer
97 views
Looking for feedback on my approach to implement an algorithm [closed]
We've recently worked with a mathematician to build us an algorithm. The algorithm will look at click data and will continuously update data associated with the user, the content, and the content's ...
3
votes
1answer
196 views
What are the best algorithms out there to retrieve data from a file system?
This is my usecase:
Traverse a filesystem, gauge its entire size and then upload it to Dropbox.
Looks quite easy and is quite easy. Now if I do it using celery and spawn a thread for each ...
3
votes
1answer
63 views
OpenGL Image Load-Store Atomics Applications
I originally asked this on plain old stack but it was closed for being too open-ended. (Which was a good call as this is a better place for such questions.)
Original Link: ...
2
votes
1answer
246 views
Try to find a word in the dictionary that has most letters given
Given some random letters , For example "a,e,o,g,z,k,l,j,w,n" and a dictionary.Try to find a word in the dictionary that has most letters given
I was going through some old interview questions and ...
1
vote
3answers
171 views
+50
Algorithm for matching similar content text items
I am working on a website (C#, ASP.Net MVC 3) which reads some RSS feeds from multiple sources and put feed title and summary in a database table(Sql Server).
What I want to do is:
Put an algorithm ...
0
votes
1answer
155 views
How can my code structure be improved? [closed]
I am looking for advice on the neatest way to structure my code.
class Password
{
private string cipher;
Password(string cipher)
{
this.cipher = cipher;
}
public string ...
0
votes
1answer
91 views
Algorithm to detect a CLICK within Square range
It might be a simple question but I am looking for optimal solution. I will have numbers printed on a screen and I will be aware of coordinates. Numbers/Symbols will have 4 points(Square) to define ...
0
votes
3answers
187 views
A simple algorithm for finding duplicate floats [closed]
We have N numbers(real numbers(float)).They can be positive or negative or anything we do not know except the fact that there is exactly one number which has a duplicate and the rest all are distinct. ...
2
votes
1answer
106 views
Algorithm for deciding change in gesture
I am developing an application where I am taking dynamic gestures as input and then mapping them to keyboard controls. By dynamic gesture, I mean for example hand moving from left to right or hand ...
0
votes
1answer
107 views
Algorithm for dividing a range into ranges and then finding which range a number belongs to
Having
a minimum
a maximum
number of ranges
a value between minimum and maximum
I'm trying to come up with a method, or two, which would calculate which range the provided value belongs to.
For ...
1
vote
1answer
107 views
Algorithm for tracking progress of controller method running in background
I am using Codeigniter framework for PHP on Windows platform. My problem is I am trying to track progress of a controller method running in background. The controller extracts data from the ...
0
votes
1answer
78 views
overworld vs on-screen 2d tile organization
I am developing a 2d game where the world is made up of tiles.
I have an overworld and a "current world":
the current world represent the current tiles on screen at any given time, currently this ...
3
votes
1answer
184 views
Addition vs multiplication on algorithm performance
I am studying about optimizing alogrithms.(Prof. Skiena's Algorithm Guide book)
One of the exercises asks us to optimize an algorithm:
Suppose the following algorithm is used to evaluate the ...
0
votes
1answer
99 views
Algorithm Identification [ String & Dictionary ]
I recently heard of an interview question:
Given a string and a dictionary. Break the string into meaningful words
and I remember solving this before with dynamic programming fairly quickly (maybe ...
1
vote
2answers
230 views
Can I use the patented Octree algorithm in a public programming challenge?
Similar to this question, but for a very different situation.
I've been working-up some example code to accompany a proposed programming challenge and asking questions about the difficult bits. In my ...
1
vote
1answer
43 views
Calculating local results from global values using SQL and PHP
I have an interesting problem for you all. I have a partial solution but I feel you guys can come up with an efficient solution.
What I have a SQL table with following structure:
StockId <- a ...
0
votes
2answers
151 views
Algorithm for picking reasonable min/max vals given a single value
I am making a simplistic in-browser IDE for some very domain-specific coding. Because I like Bret Victor's thoughts on Learnable Programming so much I thought I'd throw in some draggable numbers ala ...
1
vote
2answers
73 views
Mutual exclusion over network - pattern?
I want to do the following:
I have a number of computers. On each computer a programm will run. There is no centralized server.
The program can choose by defined criteria to give another computer ...
6
votes
3answers
201 views
A question regarding linked list vs vector insert/remove results comparison
I was reading this blog post: http://kjellkod.wordpress.com/2012/02/25/why-you-should-never-ever-ever-use-linked-list-in-your-code-again/
and I found there a code to run: http://ideone.com/62Emz
...
2
votes
1answer
152 views
How much times command executed? Looking for mistake
I have following piece of code:
int sum = 0;
for (int i = 1; i <= N; i++)
for (int j = 1; j <= N; j++)
for (int k = 1; k <= N; k = k*2)
for (int h = 1; h <= k; ...
-2
votes
1answer
107 views
Software suggestion to learn algorithms [closed]
I am interested in learning about algorithms.
I have taken algorithms course, but didn't feel I really learned as much as I would have loved to. I am looking for some interesting software which I can ...
3
votes
1answer
117 views
Print fixed width list sorted by column
I have a list of varying length where items is strings of varying length. I want to print them by (a mirrored N)/order by column.
Major points being:
Columns shall have fixed width == widest data ...
9
votes
5answers
544 views
Interview puzzle on traveling on a line segment
Here's an interesting question I came upon:
Let's just say on a number line of length M, where 0 < M <= 1,000,000,000, you given N (1 < N <= 100,000) integer pairs of points. In each ...
0
votes
2answers
160 views
What is a good algorithm for priority allocation of work duties?
I am currently doing a project (in PHP) that has the following requirements:
There is a list of people, sorted in a certain priority. Work should be allocated to them by this priority. e.g. If the ...
-4
votes
1answer
114 views
Algorithm Design Manual Question 1-7 [closed]
1-7. [3] Prove the correctness of the following recursive algorithm to multiply two natural numbers, for all integer constants c ≥ 2.
function mul(y, z)
comment Return the product yz.
if z = 0 ...
0
votes
2answers
98 views
Data structure for fast StartsWith filtering of a dictionary
I have a list of english words. I'm trying to come up with a data structure that allows me to do fast StartsWith filtering, like:
var words = dictionary.StartsWith("foo");
I was thinking of ...
5
votes
2answers
276 views
Avoid DD anomalies
I have this problem called out by PMD (static code analyzer) more often that I would like, and would like to know how someone with more experience than me would write it. My code is functional but I ...
-2
votes
1answer
88 views
Non-obvious use of graph [closed]
What are the uses of graphs that can be considered non-obvious. For many graph examples, it is very clear for people who knows even a little about graph that it can be represented as a graph, like ...
3
votes
2answers
83 views
Clustering algorithm that doesn't require predefining the number of clusters required
I have a set of user queries from a search engine that I want to cluster. The only clustering algorithm I have come across so far is the K-means clustering algorithm, which requires defining the ...
24
votes
5answers
1k views
Programming interview question on Trees
I was asked this interview question at a top internet website company recently and I kinda was stumped by it.
Certain empty glasses of water are arranged in the following order
When you pour ...
0
votes
2answers
214 views
Algorithms for data structures in distributed system
The hash table data structure can be easily spread across multiple machines with a simple algorithm to distribute the keys:
machine_to_query = item_key % machine_count
When you want to read and ...
1
vote
1answer
77 views
Auto-completion or Suggest
How does Google or amazon implement the auto-suggestion at their search box. I am looking for the most used algorithm with technology stack.
PS: I have searched over the net and found this and this ...
3
votes
3answers
140 views
Matching up articles with similar ones
I am creating a site where people can write on a niche topic. It is almost like a blog, however the area as I mentioned is a small niche with (hopefully) passionate users.
I want a functionality ...
1
vote
3answers
200 views
Should I calculate hotness of a post on request or pre-calculate it?
Here is the Reddit's hot algorithm:
cpdef double _hot(long ups, long downs, double date):
"""The hot formula. Should match the equivalent function in postgres."""
s = score(ups, downs)
...
1
vote
1answer
98 views
Implementing a sort of navigation system
So I am undertaking a project which does navigation sort of thing. So here is how the problem statement looks like.
Say, given a map of a floor, with different rooms, now somehow, this information is ...
1
vote
1answer
86 views
Turning n-dim points into m-dim where m<n and where point-to-point distance deviation is minimized
I want to apply k-means clustering to a (sparse) adjacency graph. For this I need to assign the nodes to a position in an euclidean space. Trivially I can do this by having a space with as many ...
18
votes
5answers
1k views
Can someone else patent my open-sourced algorithm?
I've written a recursive search algorithm to find the boundaries of a voxel data structure in order to render it more efficiently. I've looked around, and either it's such a simple and obvious ...
4
votes
1answer
365 views
Which string search algorithm is actually the fastest?
I have been stuck for some time on which is the fastest string search algorithm, heard many opinions, but in the end I'm not sure.
I have heard some people saying that the fastest algorithm is ...