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
.
Specifically, show the
binarytree version of the heap and the array contents after the
initial call to BUILDHEAP 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
10, 4, 15, 7, 23, 6, 15, 14, 16, 20 .
Each node contains the subarray
passed into the recursive
calls to QUICKSORT from their parent node. The root node contains
the original array A.
 3.
 Show the operation of COUNTINGSORT on the array
.
Specifically, first show
the C array after completion of the for loop in lines 67 of
the pseudocode on page 176. Then, show the B and C array after
each iteration through the for loop in lines 911.
 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 (nonasymptotically speaking). Describe any assumptions about the cost of
operations within the sorting algorithms and justify your answers.
 (a)

 (b)

 (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)
 Singlylinked list. Be sure to indicate the head of the list.
 (d)
 Doublylinked list. Be sure to indicate the head of the list.
 (e)
 Doublylinked list with sentinel. Be sure to indicate the sentinel of the list.