Dark Templar
Dark Templar

Reputation: 1137

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

Upvotes: 6

Views: 14798

Answers (5)

Markus
Markus

Reputation: 1221

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

Upvotes: 2

wildplasser
wildplasser

Reputation: 44250

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?

Upvotes: 11

Alien Life Form
Alien Life Form

Reputation: 1944

Anytime you have a key (or attribute)-value list, hash tables (AKA: associative arrays) should spring to your mind:

foo['bar']="baz";
surname['joe']="shmoe";

Hashtables generalize the concept of 1Darrays (where keys are sequential integers, and the hash function is the identity) to the case where key values can be anything and the hash function is... well, this days is something you do not get to see often, as most languages will hide the gory details of hashing from your eyes with syntax similar to the one above.

Upvotes: 0

Debkalyan
Debkalyan

Reputation: 11

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.

Upvotes: 1

Sid Malani
Sid Malani

Reputation: 2116

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.

Upvotes: 5

Related Questions