Blogs Blogs

Algorithm Blogs

Newest Most Active

It’s 5pm on Sunday evening and you decide it’s time to break out your 1st Java assignment, which is due later that evening at 12am. No big deal, you have plenty of time! What can’t you do in seven hours? I mean that’s like at least 40 games of Halo. You stall another hour (playing Halo) until six 0clock at which point you decide you better get started just in case. You glanced at the problem earlier in the week, no biggie. A couple of inputs, some basic processing, some formatted output, and maybe the professor threw in some easy twist. Two maybe three hours tops, you’ll be counting sheep by ten.   The clock strike’s ten; you have 25 IM windows open (3 hopefuls). You’ve Googled the same thing 25 times, you have more red squiggly lines than if you had written a letter in Spanish inside MS. Word, your code doesn’t compile,  and it looks like this…   public class Chaos {       //default constructor public Chaos()    ... read more

I recently tutored a student who was working on a project to develop a dictionary program in the C++ programming language. The dictionary was kept in an alphabetically sorted array, and the student was required by the exercise to use binary search to locate entries. So, he looked up the binary search algorithm in his textbook, and found an implementation that looked similar to this: int binary_search(int &A[], int key, int num_elements) { int imin = 0; int imax = num_elements - 1; // continue searching while [imin,imax] is not empty while (imax >= imin) { // calculate the midpoint for roughly equal partition int imid = midpoint(imin, imax); if(A[imid] == key) return imid; // key found at index imid else if (A[imid] < key) // determine which subarray to search // change min index to search upper subarray imin = imid + 1; else // change max index to search lower subarray imax = imid... read more

Algorithm Blogs RSS feed