Lecture14 - Computational Optimization ISE 407 Lecture 14...

Info icon This preview shows pages 1–7. Sign up to view the full content.

Computational Optimization ISE 407 Lecture 14 Dr. Ted Ralphs
Image of page 1

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

ISE 407 Lecture 14 1 References for Today’s Lecture References CLRS Section 11.1, Chapter 12 D.E. Knuth, The Art of Computer Programming, Volume 3: Sorting and Searching (Third Edition), 1998. R. Sedgewick, Algorithms in C++ (Third Edition), 1998.
Image of page 2
ISE 407 Lecture 14 2 Hash Tables We now consider data structure for storing a dictionary that support only the operations insert , delete , and search . Most data structures for storing dictionaries depend on using comparison and exchange to order the items. This limits the efficiency of certain operations. A hash table is a generalization of an array that takes advantage of our ability to access an arbitrary array element in constant time. Using hashing, we determine where to store an item in the table (and how to find it later) without using comparison. This allows us to perform all the basic operations extremely efficiently.
Image of page 3

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

ISE 407 Lecture 14 3 Addressing using Hashing Recall the array-based implementation of a dictionary from earlier. In this implementation, we allocated one memory location for each possible key. How can we extend this method to the case where the set U of possible keys is extremely large? Answer : Use hashing . A hash function is a function h : U 0 , . . . , M - 1 that takes a key and converts it into an array index (called the hash value ). Once we have a hash function, we can use the very efficient array-based implementation framework to store items in the table. Note that this implementation no longer allows sorting of the items. Questions : What hash function should we use? What do we do if two items result in the same hash value (a collision )?
Image of page 4
ISE 407 Lecture 14 4 Choosing a Hash Function What makes a good hash function? A good hash function minimizes collisions and is easy to compute . For a “random” key, we would like the probability of each hash value to be “equally likely.” This assures that the items are distributed evenly throughout the hash table. This is not as easy to accomplish as it sounds! It depends on what the distribution of possible key values is. We may not know the distribution ahead of time.
Image of page 5

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

ISE 407 Lecture 14 5 Significant Bits Two obvious hash functions are to simply consider either the first (most significant) or last (least significant) k bits of the key. How do we compute this hash function? Assume x is a w -bit integer. The index formed from the first k bits of x is the result of dividing by 2 w - k and rounding off, i.e., h ( x ) = b x/ 2 w - k c . The index formed from the last k bits of x is the remainder after dividing by 2 k , i.e., h ( x ) = x mod 2 k . Note that both of these hash functions must be used with a table of size 2 k .
Image of page 6
Image of page 7
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