Skip to main content
Search type Search syntax
Tags [tag]
Exact "words here"
Author user:1234
user:me (yours)
Score score:3 (3+)
score:0 (none)
Answers answers:3 (3+)
answers:0 (none)
isaccepted:yes
hasaccepted:no
inquestion:1234
Views views:250
Code code:"if (foo != bar)"
Sections title:apples
body:"apples oranges"
URL url:"*.example.com"
Saves in:saves
Status closed:yes
duplicate:no
migrated:no
wiki:no
Types is:question
is:answer
Exclude -[tag]
-apples
For more details on advanced search visit our help page
Results tagged with
Search options not deleted user 11582

An algorithm is a sequence of well-defined steps that define an abstract solution to a problem. Use this tag when your issue is related to algorithm design.

3 votes

Shunting-Yard algorithm implementation

I would recommend creating a Token class with specialized sub-classes for things like operators, parenthesis and values/identifiers. Your pre-defined tokens can all be saved in a Map so that you can a …
Donald.McLean's user avatar
11 votes
Accepted

Permutations of a list of numbers

The number of permutations typically increases factorially. Since 3! = 6, 4! = 24, 5! = 120, 6! = 720, 7! = 5040, 8! = 40,320, 9! = 362,880, 10! = 3,628,800, 11! = 39,916,800, 12! = 479,001,600. You …
Donald.McLean's user avatar
5 votes
Accepted

{Sum+=i++} to Reach N

What this means is that, in order to get a meaningful calculation AT ALL for 21432154197846387216432 that you would have to implement it with something else because the algorithm, as you have implemented … It's organized differently because we have to force the algorithm to work correctly without any fractional arithmetic. …
Donald.McLean's user avatar
8 votes
Accepted

Find all single elements in an array

I think this is the sort of thing for which HashSet is perfect. Your implementation would look something like I have shown below. The advantage is that you don't need a sort so your running time is st …
Donald.McLean's user avatar
6 votes
Accepted

ByteLandian challenge from CodeChef

If you don't want to recompute the overlapping sub-problems, you could use a cache. Create the cache in your class: private HashMap<int, int> resultCache = new HashMap<int, int>(); Then check it at t …
Donald.McLean's user avatar
5 votes

Detect if a tree is complete binary tree

The best solution (defined by standard practices) for any tree algorithm is almost always recursive. The tricky part is knowing how to define the algorithm in recursive terms. …
Donald.McLean's user avatar
11 votes
Accepted

Yet another prime number generator

Well, for starters, it is a proven mathematical fact that if a number is prime, it is not divisible by any prime number that is less than its square root. In your inner loop you go up to i/2 and you c …
Donald.McLean's user avatar
3 votes

Min Heap implementation with Dijkstra's algorithm

The only memory that you are allocating is the four arrays: data, index, cost, and eval. That means that if you are running out of memory then you probably need to allocate more memory. An array of pr …
Donald.McLean's user avatar
6 votes

Calculating nth power of x

The Java implementation of pow is implemented for double, rather than long, and probably uses logarithms. This makes direct comparison difficult - pow should have a more or less constant factor time, …
Donald.McLean's user avatar
13 votes

Kosaraju in Scala

That would look something like this: def main(args: Array[String]) { for (edges <- loadEdges(args)) { // the rest of the algorithm goes here // edges is a "variable" defined only within the …
Donald.McLean's user avatar