10 - Chapter 10 Hashing Data Structures and Algorithms in...

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

View Full Document Right Arrow Icon
Data Structures and Algorithms in Java Chapter 10 Hashing
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
Data Structures and Algorithms in Java 2 Objectives Discuss the following topics: Hashing Hash Functions Collision Resolution Deletion Perfect Hash Functions
Image of page 2
Data Structures and Algorithms in Java 3 Objectives (continued) Discuss the following topics: Hash Functions for Extendible Files Hashing in java.util Case Study: Hashing with Buckets
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
Data Structures and Algorithms in Java 4 Hashing To find a function ( h ) that can transform a particular key ( K ) (a string, number or record) into an index in the table used for storing items of the same type as K, the function h is called a hash function If h transforms different keys into different numbers, it is called a perfect hash function To create a perfect hash function, the table has to contain at least the same number of positions as the number of elements being hashed
Image of page 4
Data Structures and Algorithms in Java 5 Hashing
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
Data Structures and Algorithms in Java Hashing 6
Image of page 6
Data Structures and Algorithms in Java 7 Hash Functions The division method is the preferred choice for the hash function if very little is known about the keys TSize = sizeof ( table ), as in h ( K ) = K mod TSize In the folding method, the key is divided into several parts which are combined or folded together and are often transformed in a certain way to create the target address
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
Data Structures and Algorithms in Java 8 Hash Functions (continued) In the mid-square method, the key is squared and the middle or mid part of the result is used as the address In the extraction method, only a part of the key is used to compute the address Using the radix transformation , the key K is transformed into another number base; K is expressed in a numerical system using a different radix
Image of page 8
Data Structures and Algorithms in Java 9 Collision Resolution In the open addressing method, when a key collides with another key, the collision is resolved by finding an available table entry other than the position (address) to which the colliding key is originally hashed The simplest method is linear probing , for which p ( i ) = i, and for the i th probe, the position to be tried is ( h ( K ) + i ) mod TSize
Image of page 9

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

View Full Document Right Arrow Icon
Data Structures and Algorithms in Java 10 Collision Resolution (continued) Figure 10-1 Resolving collisions with the linear probing method. Subscripts indicate the home positions of the keys being hashed.
Image of page 10
Data Structures and Algorithms in Java 11 Collision Resolution (continued) Figure 10-2 Using quadratic probing for collision resolution
Image of page 11

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

View Full Document Right Arrow Icon
Data Structures and Algorithms in Java 12 Collision Resolution (continued) Figure 10-3 Formulas approximating, for different hashing methods, the average numbers of trials for successful and unsuccessful searches (Knuth, 1998)
Image of page 12
Data Structures and Algorithms in Java Collision Resolution (continued) 13
Image of page 13

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

View Full Document Right Arrow Icon
Data Structures and Algorithms in Java 14 Chaining In chaining , each position of the table is associated with a linked list or chain of structures whose info fields store keys or
Image of page 14
Image of page 15
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