next up previous


CSE 2320 Section 501 Fall 1998

Homework 2

Due: September 29, 1998, in class (September 30, 1998, 5:00pm for -10%)

1.
Show the operation of HEAPSORT on the array $A = \langle
3, 12, 5, 1, 9, 15, 2, 7, 10 \rangle$. Specifically, show the binary-tree version of the heap and the array contents after the initial call to BUILD-HEAP and after each call to HEAPIFY in line 5 of the pseudocode on page 147.

2.
The worst-case running time T(n) of the HEAPIFY algorithm is described by the recurrence on page 144. Use the substitution method to show that $T(n) = O(\lg n)$.

3.
Draw a binary tree illustrating the execution of QUICKSORT on the array $A = \langle 13, 19, 9, 5, 12, 8, 7, 4, 11, 2, 6 \rangle$. Each node contains the subarray $A[p \ldots r]$ passed into the recursive calls to QUICKSORT from their parent node. The root node contains the original array A.

4.
Show the operation of COUNTING-SORT on the array $A =
\langle 3, 2, 5, 1, 6, 5, 2, 7, 1 \rangle$. Specifically, first show the C array after completion of the for loop in lines 6-7 of the pseudocode on page 176. Then, show the B and C array after each iteration through the for loop in lines 9-11.

5.
For each of the following types of data structures, show the data structure after each insertion of the keys 4, 7, 6, 2, 4, 3 in this order.

(a)
Stack, using an array. Be sure to indicate the top of the stack.

(b)
Queue, using an array. Be sure to indicate the head and tail of the queue.

(c)
Singly-linked list. Be sure to indicate the head of the list.

(d)
Doubly-linked list. Be sure to indicate the head of the list.

(e)
Doubly-linked list with sentinel. Be sure to indicate the sentinel of the list.


next up previous