This preview shows page 1. Sign up to view the full content.
CPS 130 Assignment II: Sorting and Search Trees
Department of Computer Science  Duke University
Due on Thursday 20
th
Oct in Class
1 Give an
O
(
n
log
k
) time algorithm to merge
k
sorted lists into one sorted list, where
n
is the
total number of elements in all the input lists. (Hint: Use a minheap for
k
way merging.)
(15 points)
2 What is the worstcase running time for the bucketsort algorithm? What simple change
to the algorithm preserves its linear expected running time and makes its worstcase running
time
O
(
n
log
n
)? (15 points)
3 What does it mean for a sorting algorithm to be
stable
? Prove that COUNTINGSORT
is stable. Which of the following sorting algorithms are stable: insertion sort, merge sort
and heapsort? Give a simple scheme that makes any sorting algorithm stable. How much
additional time and space does your scheme entail? (20 points)
4 Suppose that we have numbers between 1 and 1000 in a binary search tree and want
to search for the number 363. Which of the following sequences could not be the sequence
This is the end of the preview. Sign up
to
access the rest of the document.
This document was uploaded on 01/17/2012.
 Spring '09

Click to edit the document details