{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

H35S-SectionSolutions9

# H35S-SectionSolutions9 - CS106B Winter 07-08 Handout#35S...

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

CS106B Handout #35S Winter 07-08 March 9, 2008 Section Solutions #9 Problem 1: Choosing a Good Hash Function (a) The table has 2048 buckets and yet this hash function will only place things in 26 of those buckets. And even within those 26 buckets, we will tend to get clustering around the more popular choices for the first letter of peoples' names. (b) Like above, this hash function will only use part of the available buckets, because the product of three digits only produces values is the range 0 to 729. Further, clustering will occur around some values such as 0 and no primes greater than 7 will get used. Notice our range only has 1000 values and our table has 1000 buckets, why not just map each number to the bucket with that same index. Simpler and very efficient. (c) One important feature of a hash function is that it must be stable. A given value must hash to the same result each time. Using a random number generator in this hash function means a value can hash to something different each time it is hashed. This is completely unacceptable for a hash function, because we will not be able to reliably find the bucket under which we previously stored an item! Problem 2: Understanding graph algorithms a) Lounge, Conservatory, Ball Room, Billiard Room, Library, Hall, Dining Room, Kitchen, Study b) Kitchen, Ball Room, Dining Room, Study, Billiard Room, Conservatory, Hall, Lounge, Library c) Here’s what we do: Fix distance to Lounge at 0 Process the arcs out of Lounge (Conservatory, DiningRoom, Hall) Enqueue the path: Lounge -> Conservatory (3) Enqueue the path: Lounge -> DiningRoom (4) Enqueue the path: Lounge -> Hall (8) Dequeue the shortest path: Lounge -> Conservatory (3) Fix distance to Conservatory at 3 Process the arcs out of Conservatory (BallRoom, BilliardRoom, Lounge) Enqueue the path: Lounge -> Conservatory -> BallRoom (7) Enqueue the path: Lounge -> Conservatory -> BilliardRoom (10) Ignore Lounge because its distance is fixed Dequeue the shortest path: Lounge -> DiningRoom (4) Fix distance to DiningRoom at 4 Process the arcs out of DiningRoom (BallRoom, Hall, Kitchen, Lounge) Enqueue the path: Lounge -> DiningRoom -> BallRoom (11) Enqueue the path: Lounge -> DiningRoom -> Hall (12) Enqueue the path: Lounge -> DiningRoom -> Kitchen (15)

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.

{[ snackBarMessage ]}

### Page1 / 6

H35S-SectionSolutions9 - CS106B Winter 07-08 Handout#35S...

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

View Full Document
Ask a homework question - tutors are online