This preview shows pages 1–2. Sign up to view the full content.
CSCI 4041: Algorithms and Data Structures
(Fall’09)
Homework 2, Due 10/08/09
Answer all of the following questions, and always explain your answer. Good Luck!
1. (40 points) This problem considers building a maxheap given an array of numbers. Recall that Sec
tion 6.3 in the book discusses an algorithm for building a maxheap given an array. In this problem, we
consider a different algorithm for building a maxheap. In particular, we can repeatedly use maxheap
insert, discussed in Section 6.5 in the book, to build a maxheap. Consider the following pseudocode:
Algorithm 1
MYBUILDMAXHEAP(A)
1:
heapsize(A)
←
1
2:
for
i
←
2 to
length(A)
do
3:
do MAXHEAPINSERT
(A,A[i])
4:
end for
(a) (20 points) Do the procedures BUILDMAXHEAP and MYBUILDMAXHEAP always cre
ate the same heap when run on the same input array? Prove that they do, or provide a counterex
ample.
(b) (20 points) Show that in the worst case, MYBUILDMAXHEAP requires
Θ(
n
log
n
)
time to
build a
n
element heap.
2. (60 points) This problem considers the partitioning of an array as used by QUICKSORT. Recall that
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
This is the end of the preview. Sign up
to
access the rest of the document.
This note was uploaded on 09/18/2010 for the course CSCI 4041 taught by Professor Karypis during the Spring '08 term at Minnesota.
 Spring '08
 karypis

Click to edit the document details