HW2 - Homework #2 Due Date: Wednesday, September 29th,...

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

View Full Document Right Arrow Icon
Homework #2 Due Date: Wednesday, September 29th, start of class 1. Let X be a binary search tree with height indicators located at each node. Let X 1 and X 2 be the subtrees rooted at the children of the root of X . Assuming X 1 and X 2 are height balanced AVL trees of height h 1 and h 2 respectively, give an O ( | h 1 - h 2 | + 1) algorithm to balance the whole tree without increasing its height. 2. Suppose we are given all the elements we wish to insert into an initially empty MaxHeap up front. If we insert one at a time, it takes O ( n log n ) time to build the MaxHeap. Suppose we instead build a “pre-heap” of depth d by forming a complete binary tree with each node in an arbitrary position. We must “heapify” this pre-heap so that each node has value greater than its children. (a) Suppose we take the subtrees of size 3 rooted at depth d - 1. Show how to heapify all subtrees in O ( n ) total time. (b) Assuming that all subtrees rooted at depth j are valid MaxHeaps, show how to heapify all subtrees rooted at depth j - 1 in O ( ( d - j ) n 2 d - j ) total time. (c) Analyze the running time to build a heap, using the inductive design process outlined in parts a and b . Hint: n i =1 i 2 i = O (1). 3. Aaron and Ranjan, being diabolical overlords, design a
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 12/13/2010 for the course CSCI 570 at USC.

Page1 / 2

HW2 - Homework #2 Due Date: Wednesday, September 29th,...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online