{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

CS 310 Exam 2 Review - CS 310 Exam 2 Review Furman Haddix...

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

View Full Document Right Arrow Icon
CS 310 Exam 2 Review Furman Haddix Ph.D. Assistant Professor Minnesota State University, Mankato Spring 2008
Image of page 1

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

View Full Document Right Arrow Icon
CS 310 Hash Tables Objectives Unit 9 Dynamic Sets Direct Addressing Hashing Functions Division Method Multiplication Method Universal Method (Matrix Method) Unit 10 Collisions Chaining Load Factors Open Addressing Linear Probing Quadratic Probing Double Hashing Perfect Hashing Text, Chapter 10
Image of page 2
Dynamic Sets Sets may be dynamic or static Many mathematical sets, e.g., the set of real numbers, the set of integers, the set of prime numbers, etc. are static. Many of the sets on which algorithms operate are dynamic The simplest dynamic sets are called dictionaries . Dictionaries support the following operations: element *Search(set S, key k); // returns null if no member has key k bool Insert(set S, element *x); // returns true if successful; false, otherwise bool Delete(set S, element *x); // returns true if successful; false, otherwise
Image of page 3

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

View Full Document Right Arrow Icon
Hashing Functions Although conceptually similar to a bucket, when using hash tables, the containers are referred to as slots . A slot is the location identified for a key in a hash table . A hash table is a directory in which member locations are determined by a hash function. To insert, search, and delete, there must be a way to identify the slot , this is a task accomplished by using a hash function . A hash function , h = f(k), provides a mapping for any member k of the set of keys K to a slot in a hash table. Collisions refer to cases in which more than one key hashes to the same slot
Image of page 4
Division Method h(k) = k mod m, max k >> m, where m is the number of slots Selecting m Small compared to max k Good to be prime, to avoid repeating patterns in keys Similarly, avoid m with small factors, e.g., 2 or 3 Should not a power of 2 or close to a power of 2, if low-order bit patterns are not prime, a power of 2 effectively only uses low-order bits of k n/m should not be too large so that expected number of elements per slot is not large Consider any information known about distribution of keys
Image of page 5

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

View Full Document Right Arrow Icon
Multiplication Method h(k) = m (kA - kA ) , where m is number of slots, and A is an arbitrary constant, such that 0 < A < 1. In this method, choice of m is not terribly important, other than memory utilization. Selection of A depends on characteristics of the data. One suggestion is (5 1/2 -1)/2 (Knuth, Art of Computer Programming, vol. 3), or 0.618034
Image of page 6
Universal Method The idea behind the universal method is to randomly select elements which guide the translation of a key to a hash index. If our keys have a maximum length of b bits (maximum key of 2 b ) and our indices into our table have a length of x bits; thus, our hash table has 2 x entries.
Image of page 7

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

View Full Document Right Arrow Icon
Image of page 8
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