John Mavrick's Garden

Search IconIcon to open search

Last updated April 10, 2022

Status: Tags: #cards/cmpt225/dataStructures Links: Data Structures


Hashing

Principles

?

Load factor ?

Collisions

? When multiple unique index keys are hashed to the same locations in the hash table

Preventing collisions ?

Downsides

?

Insert/Search/Remove

Open Addressing

Scenarios
Scenario 1, Empty
  1. Compute hash index h(k)
  2. Probe the resulting location (i.e. cell) in hash table, see it’s empty
  3. Cases
    • Insertion
      • insert since empty
    • Search
      • Not found
    • Remove
      • None to remove
Scenario 2, Same Element In
  1. Compute hash index h(k)
  2. Probe the resulting location (i.e. cell) in hash table, see it’s filled
  3. Cases
    • Insertion
      • Already inserted
    • Search
      • Found
    • Remove
      • Labelled ToBeDelete, needed to find other elements
Scenario 3, Diff Element In
  1. Compute hash index h(k)
  2. Probe the resulting location (i.e. cell) in hash table, see it’s filled
  3. Cases
    • Insertion
    • Search
      • Found
    • Remove
      • Labelled ToBeDelete, needed to find other elements
Scenario 4, All Locations Probed
Disadvantages

Closed Addressing (Chain Hashing)

Inserting into a chain ?

Searching a chain ?

Example

SHSL list, prepend() Image from Gyazo ? Image from Gyazo


References:

Created:: 2022-03-22 19:50


Interactive Graph