DATA STRUCTURES AND ALGORITHMS CS 3139
Lecture:  March 25th, 1999








ANNOUNCEMENTS
 


REVIEW

Sorting Algorithms and Issues

We had a lively, circus-like demonstration of the various insertion algorithms.  Thanks to all brave and eager "volunteers" who participated.
 

TODAY

More Shell sort

Heapsort
Mergesort
Quicksort!
 

SHELL SORT

Choosing increments

We provided the code that implements Shellsort.  Please see figure 7.4 in the book for the code.

Analysis of Shellsort:  The first sorting algorithm to perforn < O(N^2)

Perform pass with increment hk
    = hk insertions sorts of N/hk elements
    ==>  Pass cost  O(hk(N/hk)^2) = O(N^2/hk)
Sum over all passes
    O(Sum from i = 1 of N^2/hi)
    = O(N^2(Sum from i = 1 of 1/hi)
    = O(N^2(1+1/2+1/4+...1/(N/2))
    = O(N^2-2) = O(N^2)

An alternative way to select increments

Shell sort is very interesting from a theoritician's point of view.  In practice, other, more-efficient, algorithms are more common.
 

HEAPSORT

Problems We went through a Heapsort example in class.
 

MERGESORT
 

Example:  Merge 2 sorted lists A and B to get C
    A:    1    13    24    26
    B:    2     5     27    38
    C:    1    2    5    13    24    26    27    38             O(N-1) comparisons

Overall Algorithm

We went through a mergesort example.

Mergesort is a classic example of a Divide and Conquer algorithm.
Mergesort requires copying ==> O(N) extra storage

Mergesort Analysis


QUICKSORT
 

General idea behind Quicksort
 
 
 
 d Nhat Minh Dau, nmd13@columbia.edu