# hw2 - CSCI 4041: Algorithms and Data Structures (Fall’09)...

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 max-heap given an array of numbers. Recall that Sec- tion 6.3 in the book discusses an algorithm for building a max-heap given an array. In this problem, we consider a different algorithm for building a max-heap. In particular, we can repeatedly use max-heap- insert, discussed in Section 6.5 in the book, to build a max-heap. Consider the following pseudocode: Algorithm 1 MY-BUILD-MAX-HEAP(A) 1: heap-size(A) 1 2: for i 2 to length(A) do 3: do MAX-HEAP-INSERT (A,A[i]) 4: end for (a) (20 points) Do the procedures BUILD-MAX-HEAP and MY-BUILD-MAX-HEAP 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, MY-BUILD-MAX-HEAP 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.

### Page1 / 2

hw2 - CSCI 4041: Algorithms and Data Structures (Fall’09)...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online