hw2-soln

# hw2-soln - CSCI 4041 HW#2 Solution Key(Fall 2009 1[40pt...

This preview shows pages 1–2. Sign up to view the full content.

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.

Unformatted text preview: CSCI 4041 HW#2 Solution Key (Fall 2009) 1. [40pt] a. [20pt] BUILD-MAX-HEAP and MY-BUILD-MAX-HEAP procedures do not always create the same heap when running on the same input array. Here is the simple counterexample. Input array A = {1, 2, 3} BUILD-MAX-HEAP (A) A = {3, 2, 1} MY-BUILD-MAX-HEAP (A) A = {3, 1, 2} Note: wrong answer [-10pt] b. [20pt] We can compute a simple upper bound on the running time of MY-BUILD-MAX- HEAP as follows. Each call to MAX-HEAP-INSERT causes HEAP-INCREASE-KEY call. In other words, the running time of HEAP-INCREASE-KEY on an n-element heap is O(lg n ) because the path traced from the node updated to the root has length O(lg n ), and there O(n) such calls. Thus, the running time is O( n lg n ). We can derive a lower bound, Ω (nlgn), by observing the time considering the case that input array is strictly increasing order. In that case, the depth of node k is ⌊ lg k ⌋ . so the total time is as follows....
View Full 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-soln - CSCI 4041 HW#2 Solution Key(Fall 2009 1[40pt...

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

View Full Document
Ask a homework question - tutors are online