Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are some common examples of a Hash Table?

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

like image 609
Dark Templar Avatar asked Nov 24 '11 23:11

Dark Templar


3 Answers

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?

like image 81
wildplasser Avatar answered Oct 12 '22 00:10

wildplasser


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.

like image 20
Sid Malani Avatar answered Oct 12 '22 01:10

Sid Malani


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).

like image 20
Markus Avatar answered Oct 12 '22 01:10

Markus