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

Info icon This 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*
Image of page 1

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

View Full Document Right Arrow Icon
In the worst case, ALL /n/ entries are in the same chain. * Chain is an unordered list Every new entry is inserted at the front of the list, in /O(1)/ time. For /n/, the total time is /O(n)/ * Chain is an ordered list (entries stored in ascending order of keys)
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern