This preview shows pages 1–5. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: 15121 FALL 2009 [CORTINA/REIDMILLER]HOMEWORK 10Program due Monday, November 30 by 11:59PMWritten problems due Wednesday, December 2 by 11:59PMELECTRONIC HANDIN AVAILABLE BY MONDAYPROBLEMS (10 pts)a.(1.5 pt) A Dateobject consists of a month (an int) and a day (an int). A hash table stores Dateobjects in an array of length 10 using the following hashing function: (month + day) % 10b.The following dates are added to an initially empty hash table in the order shown: c.1/1 (January 1) d.1/18 (January 18) e.2/10 (February 10) f. 3/31 (March 31) g.4/18 (April 18) h.6/13 (June 13) i. 9/24 (September 24) Show the resulting hash table with chaining (buckets) to resolve collisions. j. If the hash table represents a Set and duplicates are not allowed, should the chain of dates objects be maintained in unsorted or sorted order? Explain. k.(1 pt) Consider a hash function H(k) that returns an index into a hash table given a key k. You have a 50cell hash table indexed from 0 to 49. The keys are positive integers. l. Alice proposes the following hash function: H(k) = (int)(Math.random()*50). Explain why this hash function is a poor choice. m.Bob proposes the following hash function: H(k) = the sum of the digits in key k. Explain why this hash function is a poor choice. n.(1.5 pts) Consider the minheap below: 18/ \34 26/ \ / \60 46 52 44/ \ 88 75o.Using the minheap above, add the value 23 and restore the heap using the algorithm discussed in lecture. For your answer, show how the resulting heap would be stored in an array. p.Using the originalminheap above, remove the minimum value and restore the heap using the algorithm discussed in lecture. For your answer, show how the resulting heap would be stored in an array. q.Why are binary search trees not usually stored using arrays? Explain. r.(2 pts) s.You are given the following array of integers in the order shown: 45 24 30 58 82 64 92 12 36 (corrected)Trace the algorithm for building a maxheap out of an array of elements, showing the contents of the array after each value is "inserted" into the maxheap. Use a vertical line to separate the elements in the array that are part of maxheap with those that are not. The first four steps are shown below for you along with the corresponding maxheaps. You do not have to draw the maxheaps in your answer. 45  24 30 58 82 64 92 12 36 4545 24  30 58 82 64 92 12 36 45/2445 24 30  58 82 64 92 12 36 45/ \24 3058 45 30 24  82 64 92 12 36 58/ \45 30/24t. Using your heap from part (a), trace the Heap Sort algorithm to transform the array to a sorted array in increasing order. Show the contents of the array each time the element in index 1 (the root of the heap) is moved to its...
View
Full
Document
 Spring '09
 ReidMiller

Click to edit the document details