1 / 28

Dictionaries

Dictionaries. A Dictionary is a set S made up of n elements: x 0 x 1 x 2 x 3 … x n-1 that has the following functions. Functions: createEmptySet() returns a newly created empty set lookUp(S, k) returns the node in S that has the key k

Download Presentation

Dictionaries

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Dictionaries A Dictionary is a set S made up of n elements: x0 x1 x2 x3 … xn-1 that has the following functions. Functions: createEmptySet() returns a newly created empty set lookUp(S, k) returns the node in S that has the key k insert(S, x) returns S with x added delete(S, k) returns S with x (found using x.k) removed isEmptySet(S) returns true if S is empty and false if it is not

  2. Homework 7 • Describe how to implement a dictionary that has an average lookUp, insert, and delete time that is constant, but uses an array of no more than 2*n elements. • Do the five Dictionary functions.

  3. A Node NameLast: Smart FirstName: Joe StudentNumber: 8 SSN: 123341112 Grade: 95

  4. Hash Table 1123 2876 4468 9867 4312

  5. Hash Table hash function 1123 2876 4468 9867 4312

  6. Hash Function h(key)  position in the array • Last 4 of SSN for an array of size 10,000. • The modulo function is good to use for two reasons. • Lets you fit key to any size array. • If you use a prime number, it helps your distribution.

  7. h(key) = key mod 17 1123 2876 4468 9867 4312

  8. Collisions 3454 1123 2876 4468 9867 4312

  9. Separate Chaining

  10. Linear Probing Add: 5 7 14 22 24 39

  11. Linear Probing Add: 7 14 22 24 39 5

  12. Linear Probing Add: 14 22 24 39 5 7

  13. Linear Probing Add: 22 24 39 5 7 14

  14. Linear Probing Add: 24 39 22 5 7 14

  15. Linear Probing Add: 24 39 5 22 7 14

  16. Linear Probing Add: 39 5 22 7 24 14

  17. Linear Probing Add: 5 22 7 24 39 14

  18. Primary Clustering 5 22 7 24 39 14

  19. Double Hashing H(key, 0) = h(key) H(key, p+1) = (H(key, p) + h2(key)) mod m

  20. Double Hashing 39 h2(key) = addDigits(key) 5 7 22 24 14

  21. Double Hashing Add: 5 7 14 22 24 39

  22. Double Hashing Add: 7 14 22 24 39 5

  23. Double Hashing Add: 14 22 24 39 5 7

  24. Double Hashing Add: 22 24 39 5 7 14

  25. Double Hashing Add: 24 39 22 5 7 14

  26. Double Hashing Add: 24 39 5 7 22 14

  27. Double Hashing Add: 39 5 7 22 24 14

  28. Double Hashing 39 Add: 5 7 22 24 14

More Related