# Search Results

• ### dijkstra/prim's algorithm...a little help?

##### - by bfpri
I was wondering for dijkstra's and prim's algorithm, what happens when they are choosing between more than one vertex to go to ,and there are more than one vertex with the same weight. For example

• ### What is an algorithm for joining PCM files?

##### - by Ole Jak
What is an algorithm for joining PCM files? I have several PCM files I need to Join them in a way like speakers are speac at the same time. So How to Join PCM files?

• ### Roulette wheel selection algorithm

##### - by swati
Can anyone provide some pseudo code for a roulette selection function? How would I implement this: I don't really understand how to read this math notation.I want General algorithm to this.

• ### What Sorting Algorithm Is Used By LINQ "OrderBy"?

##### - by Mystagogue
Evidently LINQ's "OrderBy" had originally been specified as unstable, but by the time of Orca it was specified as stable. Not all documentation has been updated accordingly - consider these links: Jon Skeet on OrderBy stability Troy Magennis on OrderBy stability But if LINQ's OrderBy is now "stable," then it means it is not using a quicksort (which is inherently unstable) even though some documentation (e.g. Troy's book) says it is. So my question is: if not quicksort, then what is the actual algorithm LINQ's orderBy is using?

• ### Java Algorithm HmacSHA256 not available

##### - by user324929
Hi, I am trying an encryption-decryption code in java. When I am trying to run it with JDK and code in class with main method it is running fine. But when I am trying to run same code in Tomcat, tomcat is throwing exception: java.security.NoSuchAlgorithmException: Algorithm HmacSHA256 not available. Can anybody guide me to proper direction please? Thank you.

• ### Most efficient algorithm for merging sorted IEnumerable<T>

##### - by franck
Hello, I have several huge sorted enumerable sequences that I want to merge. Theses lists are manipulated as IEnumerable but are already sorted. Since input lists are sorted, it should be possible to merge them in one trip, without re-sorting anything. I would like to keep the defered execution behavior. I tried to write a naive algorithm which do that (see below). However, it looks pretty ugly and I'm sure it can be optimized. It may exist a more academical algorithm... IEnumerable<T> MergeOrderedLists<T, TOrder>(IEnumerable<IEnumerable<T>> orderedlists, Func<T, TOrder> orderBy) { var enumerators = orderedlists.ToDictionary(l => l.GetEnumerator(), l => default(T)); IEnumerator<T> tag = null; var firstRun = true; while (true) { var toRemove = new List<IEnumerator<T>>(); var toAdd = new List<KeyValuePair<IEnumerator<T>, T>>(); foreach (var pair in enumerators.Where(pair => firstRun || tag == pair.Key)) { if (pair.Key.MoveNext()) toAdd.Add(pair); else toRemove.Add(pair.Key); } foreach (var enumerator in toRemove) enumerators.Remove(enumerator); foreach (var pair in toAdd) enumerators[pair.Key] = pair.Key.Current; if (enumerators.Count == 0) yield break; var min = enumerators.OrderBy(t => orderBy(t.Value)).FirstOrDefault(); tag = min.Key; yield return min.Value; firstRun = false; } } The method can be used like that: // Person lists are already sorted by age MergeOrderedLists(orderedList, p => p.Age); assuming the following Person class exists somewhere: public class Person { public int Age { get; set; } } Duplicates should be conserved, we don't care about their order in the new sequence. Do you see any obvious optimization I could use?

• ### Algorithm to find lenth of longest sequence of blanks in a given string

##### - by Venki
Looking for an algorithm to find the length of longest sequence of blanks in a given string examining as few characters as possible? Hint : Your program should become faster as the length of the sequence of blanks increases. I know the solution which is O(n).. But looking for more optimal solution

• ### Google search results : How to find the minimum window that contains all the search keywords?

##### - by Algorist
Hi, I was wondering what will the complexity of the algorithm that is used to find the smallest snippet that contains all the search key words. Please explain the complexity, if non-trivial. Thanks Bala

• ### Help with this algorithm

##### - by user146780
I want to implement this algorithm here: http://bellard.org/pi/pi_n2/pi_n2.html but I don't understand a good part of it, and would like to understand. Could someone please put it in understandable words, psudocode, or C. Thanks.

• ### Diamond square algorithm.

##### - by Gabriel A. Zorrilla
I'm trying to write the Diamond-Square algorithm in Java to generate a random map but can't figure out the implementation... Anyone with some Java code (or other language) so i can check how the loop is made would be greatly appreciated! Thanks!

##### - by user115621
Hello, I have map (openstreetmap project) with many buildings. Each building is a polygon. How can I make saddle roof parts polygons for every building outline? Algorithm should transform one polygon in 2D to set of polygons in 2D (or 3D). Reason for this transformation is visualization - better rendering isometric view. For example (shading isn't important): Thanks

• ### How does Dijkstra's Algorithm and A-Star compare?

##### - by KingNestor
I was looking at what the guys in the Mario AI Competition have been doing and some of them have built some pretty neat Mario bots utilizing the A* (A-Star) Pathing Algorithm. (Video of Mario A* Bot In Action) My question is, how does A-Star compare with Dijkstra? Looking over them, they seem similar. Why would someone use one over the other? Especially in the context of pathing in games?

• ### Running time for Dijkstra's algorithm on a priority queue implemented by sorted list/array

##### - by jay
So I'm curious to know what the running time for the algorithm is on on priority queue implemented by a sorted list/array. I know for an unsorted list/array it is O((n^2+m)) where n is the number of vertices and m the number of edges. Thus that equates to O(n^2) time. But would it be faster if i used an sorted list/array...What would the running time be? I know extractmin would be constant time.

• ### Need XOR Encryption Algorithm Pseudocode

##### - by ritch
I am trying to find the pseudocode for the XOR encryption algorithm. However I've had no luck so far. Anybody know where I can find it? EDIT: XOR 32 if that helps

• ### Algorithm to generate a segment maze

##### - by rlbond
I want to generate a maze that looks like this: That is, it consists of paths in one direction that are then connected. I have looked for an algorithm to generate mazes like this without success.

• ### Archery game programming algorithm

##### - by Ricky
I need the algorithm to animate the arrow based on 2 parameters, angle while shooting and power while drawing the bow. Ive tried to use y=asinx but it works only when shooting in up direction. Doesnt work well while shooting with straight or down direction. Thanks.

• ### Algorithm for Fogbugz pricing scheme

##### - by Anon1865
Hi, I'm looking for an algorithm to calculate total cost of licenses purchased based on the "FogBugz for your server" pricing scheme (http://www.fogcreek.com/FogBugz/PriceList.html). Fogbugz pricing is: 1 License \$299 5 License Pack \$999 10 License Pack \$1,899 20 License Pack \$3,499 50 License Pack \$7,999 If you ask a quote for let's say 136 licenses they calculate it as \$22,694. How can I do this in C# or LINQ? Any help will be appreciated.

• ### Time complexity of a recursive algorithm

##### - by Passonate Learner
How can I calculate the time complexity of a recursive algorithm? pow1(x,n) if(n==0){ return 1 } else{ return x * pow1(x, n-1) } pow2(x,n) if(n==0){ return 1 } else if(n is odd integer){ p = pow2(x, (n-1)/2) return x * p * p } else if(n is even integer){ p = pow2(x, n/2) return p * p }

• ### Critical Path Method Algorithm

##### - by nunos
Where can I find a Java implementation of the Critical Path Method Algorithm? I am sure there's some implementation in the cloud. Thanks in advance.

• ### cool project to use a genetic algorithm for?

##### - by Ryan
I'm looking for a practical application to use a genetic algorithm for. Some things that have thought of are: Website interface optimization Vehicle optimization with a physics simulator Genetic programming Automatic test case generation But none have really popped out at me. So if you had some free time (a few months) to spend on a genetic algorithms project, what would you choose to tackle?

• ### Calculating length of objects in binary image - algorithm

##### - by Jacek
I need to calculate length of the object in a binary image (maximum distance between the pixels inside the object). As it is a binary image, so we might consider it a 2D array with values 0 (white) and 1 (black). The thing I need is a clever (and preferably simple) algorithm to perform this operation. Keep in mind there are many objects in the image. The image to clarify: Sample input image:

• ### Which algorithm takes minimum time to sort?

##### - by Venkats
Using Big Oh notation, which sorting algorithm takes minimum amount of time to sort the following numbers: 9834, 343, 902, 23922, 7233, 82, 299, 23, 4454, 2342, 992, 389.

• ### Justifying UIVIews on the iPhone: Algorithm Help

##### - by coneybeare
I have been messing around with a way to justify align a collection of UIView subclasses within a containing view. I am having a little bit of trouble with the algorithm and was hoping someone could help spot my errors. Here is pseudocode of where I am now: // 1 see how many items there are int count = [items count]; // 2 figure out how much white space is left in the containing view float whitespace = [containingView width] - [items totalWidth]; // 3 Figure out the extra left margin to be applied to items through items[count-1] float margin = whitespace/(count-1); // 4 Figure out the size of every subcontainer if it was evenly split float subcontainerWidth = [containingView width]/count; // 5 Apply the margin, starting at the second item for (int i = 1; i < [items count]; i++) { UIView *item = [items objectAtIndex:i]; [item setLeftMargin:(margin + i*subcontainerWidth)]; } The items do not appear to be evenly spaced here. Not even close. Where am I going wrong? Here is a shot of this algorithm in action: EDIT: The code above is pseudocode. I added the actual code here but it might not make sense if you are not familiar with the three20 project. @implementation TTTabStrip (JustifiedBarCategory) - (CGSize)layoutTabs { CGSize size = [super layoutTabs]; CGPoint contentOffset = _scrollView.contentOffset; _scrollView.frame = self.bounds; _scrollView.contentSize = CGSizeMake(size.width + kTabMargin, self.height); CGFloat contentWidth = size.width + kTabMargin; if (contentWidth < _scrollView.size.width) { // do the justify logic // see how many items there are int count = [_tabViews count]; // 2 figure out how much white space is left float whitespace = _scrollView.size.width - contentWidth; // 3 increase the margin on those items somehow to reflect. it should be (whitespace) / count-1 float margin = whitespace/(count-1); // 4 figure out starting point float itemWidth = (_scrollView.size.width-kTabMargin)/count; // apply the margin for (int i = 1; i < [_tabViews count]; i++) { TTTab *tab = [_tabViews objectAtIndex:i]; [tab setLeft:(margin + i*itemWidth)]; } } else { // do the normal, scrollbar logic _scrollView.contentOffset = contentOffset; } return size; } @end

• ### A leader election algorithm for an oriented hypercube

##### - by mick
I'm stuck with some problem where I have to design a leader election algorithm for an oriented hypercube. This should be done by using a tournament with a number of rounds equal to the dimension D of the hypercube. In each stage d, with 1 <= d < D two candidate leaders of neighbouring d-dimensional hypercubes should compete to become the single candidate leader of the (d+1)-dimensional hypercube that is the union of their respective hypercubes.