set7_sol

set7_sol - CS112 Spring 2011: Problem Set 7 Hash table - 1....

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

View Full Document Right Arrow Icon
CS112 Spring 2011: Problem Set 7 Hash table ------------------------------------------------------------------------ 1. You are given the following keys to be hashed into a hash table of size 11: 96, 43, 72, 68, 63, 28 Assume the following hash function is used H(key) = key mod 11 and chaining (array of linked lists) is used to resolve collisions. 1. Show the hash table that results after all the keys are inserted. 2. Compute the average number of comparisons for successful search. *SOLUTION* 1. 0 []->/ 1 []->/ 2 []->68->/ 3 []->/ 4 []->/ 5 []->/ 6 []->28->72->/ 7 []->/ 8 []->63->96->/ 9 []->/ 10[]->43->/ 2. The average number of comparisons for successful search is: (1+1+2+1+2+1)/6 = 4/3 ------------------------------------------------------------------------ 2. Using chaining to resolve collisions, give the worst-case running time (big O) for inserting /n/ keys into an initially empty hash table table for each of the following kinds of chains: * Chain is an unordered list * Chain is an ordered list (entries stored in ascending order of keys) * Chain is an AVL tree (ordered by keys) *SOLUTION*
Background image of page 1

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

View Full DocumentRight Arrow Icon
In the worst case, ALL /n/ entries are in the same chain.
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This document was uploaded on 11/01/2011 for the course 198 112 at Rutgers.

Page1 / 3

set7_sol - CS112 Spring 2011: Problem Set 7 Hash table - 1....

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

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