CSE 373 Winter 2003

Assignment #5 Due February 28

This assignment will let you get more acquainted with Big Oh, Omega and Theta and recurrence relations. You'll also get to know your sorting algorithms.

1. (10 points).
Show that f(N) = 12 N2 + 25 N + 500 logN is Theta(N2) by showing that it is both O(N2) and Omega(N2) (cf. Weiss pp 29-31). Do this by selecting appropriate constants for n0 and c for O and Omega.

2. (10 points).
What is the running time (in big Oh notation) of the following recursive function?

Thirds (int N) : int {
   if (N < 3) then {
       return 1;}
   else {
       return Thirds(N/3) + Thirds(N/3) + Thirds(N/3); }
}
First, write down the recurrence relation and then solve it by expanding the terms (it might be convenient to assume that N = 3k)

3. (30 points)

4. (3 points) Weiss 7.2.

5. (5 points) There are two strategies for handling small arrays in Quicksort.

The first strategy is the one described in class (cf. Lecture 14 Slide 29). Apply Quicksort recursively until the array is smaller than a CUTOFF size, then call Insertionsort to sort the small array.

A second strategy is to apply Quicksort recursively until the array is smaller than the CUTOFF, as above, but then return. In this strategy after Quicksort(A[],1,n) is completed, the array A[1,n] is almost sorted. Now call Insertionsort(A[],1,n) to finish the job. Since A[1..n] is almost sorted then Insertionsort should do a good job.

Explain why the number of comparisons executed by Insertionsort in the two strategies is the same.



This document was generated by Jean-Loup Baer on February, 21 2003 using texi2html