4 Problems on Binary Heap - Assignment 5 | CMSC 351, Assignments of Algorithms and Programming

Material Type: Assignment; Professor: Kruskal; Class: Algorithms; Subject: Computer Science; University: University of Maryland; Term: Summer I 2009;

Typology: Assignments

Pre 2010

Uploaded on 07/29/2009

koofers-user-eky
koofers-user-eky 🇺🇸

10 documents

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Summer 2009 CMSC 351: Homework 5 Clyde Kruskal
Due at the start of class Friday, June 19, 2009.
Problem 1. Consider an array of size eight with the numbers in the following order
20,40,60,80,10,30,50,70.
(a) What is the array after heap formation? How many comparisons does the stan-
dard algorithm use?
(b) Show the array after each element sifts down after heap creation. How many
comparisons does the standard algorithm use for all of the sifts?
(c) How many comparisons does the modified algorithm (Floyd’s version) use to
create the heap?
(d) How many comparisons does the modified algorithm (Floyd’s version) use for the
remainder of the sort?
Problem 2. Ad-ary heap is like a binary heap, but instead of two children, nodes have d
children.
(a) How would you represent a d-ary heap in an array?
(b) What is the height of a d-ary heap of nelements in terms of nand d.
(c) Explain loosely (but clearly) how to extract the maximum element from the d-ary
heap (and restore the heap). How many comparisons does it require?
(d) How many comparisons does it take to sort? Just get the high order term exactly,
but show your calculations.
(e) What value(s) of dare optimal? Justify your answer.
Problem 3. Assume nis a p ower of 2. If you view heap creation as a recursive procedure,
you get approximately the following recurrence for the number of comparisons:
T(n) = (2T(n/2) + 2 lg nif n > 1
0 if n= 1
(a) Use constructive induction to show that T(n) = an +blg n+c. Find constants
a,b, and c.
(b) Solve the recurrence using the iteration method.
Problem 4. Do Exercise 6.5-8 on page 142 of CLRS.

Partial preview of the text

Download 4 Problems on Binary Heap - Assignment 5 | CMSC 351 and more Assignments Algorithms and Programming in PDF only on Docsity!

Summer 2009 CMSC 351: Homework 5 Clyde Kruskal

Due at the start of class Friday, June 19, 2009.

Problem 1. Consider an array of size eight with the numbers in the following order 20 , 40 , 60 , 80 , 10 , 30 , 50 , 70.

(a) What is the array after heap formation? How many comparisons does the stan- dard algorithm use? (b) Show the array after each element sifts down after heap creation. How many comparisons does the standard algorithm use for all of the sifts? (c) How many comparisons does the modified algorithm (Floyd’s version) use to create the heap? (d) How many comparisons does the modified algorithm (Floyd’s version) use for the remainder of the sort?

Problem 2. A d-ary heap is like a binary heap, but instead of two children, nodes have d children.

(a) How would you represent a d-ary heap in an array? (b) What is the height of a d-ary heap of n elements in terms of n and d. (c) Explain loosely (but clearly) how to extract the maximum element from the d-ary heap (and restore the heap). How many comparisons does it require? (d) How many comparisons does it take to sort? Just get the high order term exactly, but show your calculations. (e) What value(s) of d are optimal? Justify your answer.

Problem 3. Assume n is a power of 2. If you view heap creation as a recursive procedure, you get approximately the following recurrence for the number of comparisons:

T (n) =

{ 2 T (n/2) + 2 lg n if n > 1 0 if n = 1

(a) Use constructive induction to show that T (n) = an + b lg n + c. Find constants a, b, and c. (b) Solve the recurrence using the iteration method.

Problem 4. Do Exercise 6.5-8 on page 142 of CLRS.