CSE 2320 Section 501 Fall 1998

**Homework 2**

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

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

- 1.
- Show the operation of HEAPSORT on the array
.
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 . - 3.
- Draw a binary tree illustrating the execution of QUICKSORT on
the array
.
Each node contains the subarray
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
.
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.