Algorithms, Recursion and Data-Structures

Princeton Algorithm Courses

One of the problems I had with setting up the jar file algs4.jar was that the CLASSPATH variable needs to include the directory where your Java programs .class file is. You can include ‘.’ in CLASSPATH to indicate that the current directory should be included. Then I followed the instructions on the book site. and modified my .bash_profile as follows.

Recursive Algorithms

A method can call itself. There are three important rules of thumb in developing recursive programs:

The recursion has a base case – always includes a conditional statements as the first statement in the program that has a return.

Recursive calls must address subprograms that are smaller in some sense, so that recursive calls converge to the base case.

Recursive calls should not address subprograms that overlap.

Greatest Common Divisor

Euclid’s Algorithm – compute the greatest common divisor of two nonnegative integers p and q as follows: If q is 0, the answer is p. If not, divide p by q and take the remainder r. The answer is the greatest common divisor of q and r.