reading-notes

401 class 30 notes

Hash Tables

Hash tables are like an old school Blockbuster movie rental shop, where the employee stocking the shelves takes a look at the incoming movies (VHS, of course), and organizes them on the shelves alphabetically by title (title being the “key”). The employee also gives each film an “index” number based on where they are on the shelf.

Sometimes, however, the employee receives a new title that has the same title (key) as an existing movie (this is a “collision”) - for example Delirious from 1991 and another from 2007, or remakes with the same title. When that happens, the employee “chains” the films together by placing the new film behind the old film at the index space the old title is in, and the films can then be found by the year they were made (their “value”).

When a movie is requested, the employee can then just find where a film is located based on its shelf index number, and then by year (value) if it’s in an index space with collisions.

Source


Things I Want To Know More About:

Nothing at the moment!