Dating nerds entails many wonderful things. I do love the sparkle in someone’s eyes when they tell me how fascinating sorting algorithms are. But when they start detailed discussions on the best Magic card in the new set, I get lost.
In situations like these, it is good to have a joker up your sleeve, some way to turn the conversation. My trick for these situations is nerd sniping. The idea is to introduce a problem or interesting concept that captures their attention. It should be easy to talk about, but complex enough to keep their interest for more than five minutes (or long enough to steer them away from Magic cards).
One proven way to snipe your nerd’s attention is to explain hash tables. They are a fancy, yet easy to explain concept from computer science and perfect for some nerd sniping. If you do not yet know how to explain hash tables, don’t worry, here is a quick guide.
- Explain the Basics
Start with the basics: hash tables are data structures that store data packages. These packages can have any size, so they might be a single number or the encyclopaedia Britannica. The point of hash tables is to have a designated spot for each package, so you can find it again.
2. Use an Illustration
If you explain hash tables, you might use an example to illustrate it. I like to compare them to libraries. In many ways, hash tables resemble bookshelves, that are separated into single cells. Each cell can contain one book. As in hash tables, it is important in libraries to have a system that allows you to find a book quickly within kilometres of bookshelves.
3. How to make sure you find your package
If a user looks for a certain book, they get a shelf marker that tells them the book’s position within the library. With hash tables it is similar. Every package has a key, with which you can find the package in the table.
The key is transformed into the hashed key using the hash function. The hashed key indicates the position in the table.
In a library, the key would be the book’s title and author that are transformed into the book’s shelf marker. When the library acquires new books, the shelf maker is generated by a librarian who then brings it to its new position. In hash tables, it is the same, just without the librarian. The data package is assigned to a cell, according to the hashed key.
4. The magic of hashing
You might get the question: why do I need the hash function, can I not just put the data packages in the table? The answer is: because you want to be able to find the packages again. If you just put them in the table without a system, you will soon be lost. Moreover, hash tables get slower the fuller they are. That means you also want to avoid bulks of filled cells. Therefore, we need the hash function. It generates hashed keys, in a way that they do not cluster at certain points.
5. How to deal with conflict
Whilst filling the hash table, you will encounter the problem that a package is supposed to go into an already taken slot. The probability of such collisions rises as the hash table fills up. Some hash tables allow multiple packages in one cell (e.g. hashing with chaining), but many do not.
When we imagine a librarian in a classic library sorting books in a shelf, she will place the book in the correct position by pushing the other books to the side. In a hash table-like library that would be a lot of work because the librarian would have to move each book one slot further until she reaches the next free slot. The method is called Robin-Hood-Hashing and leads to very tidy shelves: the books are perfectly ordered by their shelf marker.
To save time, the librarian could also just go right, down the shelf and look for the next free cell. Users will still be able to find the book when they go to the location indicated by the shelf marker and look to the right. If they get to a free cell before finding the book, they know it is currently on loan. The professional term for this is Linear Probing.
Proof of concept
Whilst writing this post, I gave my quick guide to several friends dating nerdy. They used it and explained hash tables to their dates and partners. The reports varied slightly, but all nerds successfully sniped, some even swept from their feet.
It also works the other way around: If you are the nerdy part of your date and you are looking for an interesting, witty conversation topic, maybe try hash tables. I know from personal experience, that it worked at least once.
LEILAH JAETZOLD MAIER
The Master of Hash Tables
The nice nerd who explained hash tables to me is Tobias Maier. He is doing his PhD in theoretical computer science at the Karlsruhe Institute for Technology and can spend hours discussing magic cards if you do not switch the topic.