Monday, February 22, 2010

Data Structures and Algorithms

Data Structures and Algorithms

I found this website which contains various animations of the algorithms covered in a typical data structures course. In addition to providing the code it also highlights which particular lines are active during the animation.



Examples:

In addition, complexity analysis of algroithms are also included. The following postscript contains the explanation as well as the mathematics underlying the process of the analysis. Also on page 4 are examples of actual algorithms and the analysis process.

Complexity

The codes are written in Java. I'm not sure how many people are familiar with Java but figured I might post some key concepts.

Example:
public void buildHeap(int[] a) {
     for (int i = a.length/2; i>0; i--) {
       heapify(a,i);
     }
}
The "public" component declares that the method will be publically acessible to outside classes. Another declaration would be "private" which would be similar to def __methodName(self,a) in python.

The "void" component declares that the method will not be returning anything. Usually this declaration is used when instance variables are being modified. Another declaration would be to declare the variable being returned. An example would be public int[] buildHeap(int[] a). This would essentially declare that the method buildHeap will return an array of contents integer data types with an integer array data type as its paramater with variable name "a".

The "int[] a" component declares that the paramater being sent to the method is an array containing the integer data type for its contents. The "a" component declares the variable name, similar to def methodName(self,a) in python.

The for loop is declaring that the integer i is being decremented by 1 from initial condition of the length of a/2 to i<=0. In other words, running only while the condition i>0 is true.

No comments:

Post a Comment