What are some common examples of a Hash Table?

11,830

Solution 1

A real world example: Suppose I stay in a hotel for a few days, because I attend a congress on hashing. At the end of the day, when I return to the hotel, I ask the desk clerk if there are any messages for me. Behind his back is a dovecot-like cupboard, with 26 entries, labeled A to Z. Because he knows my last name, he goes to the slot labeled W, and takes out three letters. One is for Robby Williams, one is for Jimmy Webb, and one is for me.

The clerk only had to inspect three letters. How many letters would he have to inspect if there would have been only one letter box?

Solution 2

When I want a user record in memory searchable by ID.

An alternative will be a list. But every time I would have to loop to find the User. Hash table will give me a user object in just one call.

Solution 3

A cache, where in if new data comes in we overwrite the existing record using the key.So basically the cache would be used to store the most recent state.

Solution 4

When you go ice skating and you swap your shoes for ice skates. They take your shoes, put them in the ice skates box that includes your size, and give you the ice skates and a token which has the size (hash) and the shoe pair number (element in the hash box).

Share:
11,830
Dark Templar
Author by

Dark Templar

Updated on June 04, 2022

Comments

  • Dark Templar
    Dark Templar about 2 years

    I was just wondering if there were some "standard" examples that everyone uses as a basis for explaining the nature of problem that requires a Hash table. What are some well-known problems in the real world that can see great benefits from using a Hash table?

    *EDIT: also, a little background or explanation as to why the problem's nature benefits with a Hash Table would be of help! Thanks