next up previous


CSE 2320 Section 501/571 Fall 1999

Homework 2

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

1.
Show the operation of HEAPSORT on the array $A = \langle
10, 4, 15, 7, 23, 6, 15, 14, 16, 20 \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.
Draw a binary tree illustrating the execution of QUICKSORT on the array $A = \langle$ 10, 4, 15, 7, 23, 6, 15, 14, 16, 20 $\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.

3.
Show the operation of COUNTING-SORT on the array $A =
\langle 2, 6, 3, 8, 1, 4, 7, 3, 3, 6 \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.

4.
For each of the following arrays, select which of the five sorts INSERTSORT, MERGESORT, HEAPSORT, QUICKSORT or COUNTINGSORT (as implemented in the textbook) will run fastest (non-asymptotically speaking). Describe any assumptions about the cost of operations within the sorting algorithms and justify your answers.

(a)
$\langle 10, 4, 15, 7, 23, 6, 15, 14, 16, 20 \rangle$

(b)
$\langle 2, 6, 3, 8, 1, 4, 7, 3, 3, 6 \rangle$

(c)
Array A[1..100], where A[i] = 1000(101 - i).

5.
For each of the following types of data structures, show the final data structure after inserting the keys 4, 2, 6, 7, 6, 5 in this order into an initially empty data structure.

(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