# Using "Hash Tables" for faster retrieval

I’ve been lurking for awhile an occasionally posting. I work in IT, and I used to do a lot of programming. One of the topics I was reading here recently was discussing how to quickly access items stored in a memory palace. One of the suggestions was to number every 5th location by associating some shape like: 5 = hook, snake, Superman, seahorse, a wave or water. Then jump to the closest memory location at for example 15 then work backward to get whatever is stored at 13.

There is a very similar problem in computer science when you have a data table which stores information at an index. So we might store information about Jacob, age 23, blonde, blue eyes, etc. at index number 13. A computer might start at index 1 and compare it to Jacob, and move on to 2, 3, 4 etc until it arrives at Jacob in index 13. This is called a linear search and isn’t very efficient, especially as the table gets bigger.

So to get around this issue programmers have developed something called a “hash table”. The way this works is you take something about the data, in this example we used Jacob and we create a hash function that when fed in the name jacob will return the index jacob is stored at. So we might add up the acsii values of the letters, 106+97+99+111+98= 511. We take 511*.025 = 12.775 round that up to 13 and go straight to Jacob at index 13. Because you always use the hash function to calculate the index of a search term, you’ll always find Jacob.

If you use the same hash function on a different name and it returns index 13, then in the computer you’d use another data structure called a linked list to connect that name to Jacob. So you’d have to look through stuff linked into index 13, but that would be quicker than going through the whole list from index zero to the end.

So I began to wonder if this type of thing could be used to gain faster access to data in your memory palace.

I haven’t really worked out how you could implement an efficient hash function in your head. It could be something as easy as having a number of memory palaces, and if it is related to food, the memory palace is the shopping centre, which has 26 aisles A-Z, so you’d quickly jump to the right palace and the correct aisle and do a quick walk down it to find what you want.

But a better hashing function would allow for more spread and less linking, so you might be able to jump straight to what you want.

Thoughts?

2 Likes

@rdearman, I like making connections between programming concepts and mnemonic systems. You can check out my analysis documents on github to see some of my thinking. And I’ve taught many programming classes, so I have the basics well ingrained. You bring up a very good thought about using a hashing function that intrigues me as a common structure I haven’t had a good name for yet.

There are two basic mnemonic systems: the story, and the peg. That’s all. The variations are many. The story is just a linked list, and the peg is based most often on sequential storage of images. The peg itself is an ordered index and unlike a computer, we can use other ordering rules instead of numeric order.

The hash function acts to keep things sorted as new pieces of data are added, selecting the right bin to store data in. Selecting too small of a set of indices or too large results in too full bins or a sparse structure. Similarly, selecting too small of a peg system, say from one to ten, results in a need to deposit too many items at one peg. And using a large peg structure usually overwhelms the memory of the user as it disintegrates over time.

Your idea of using the alphabet for the peg system would have 26 bins. Maybe you want to remember a sorted list of food recipes that you know, or music pieces that you play (@meepster was interested in this). The hash function would have to standardize how you described the recipe or music piece. Then, most likely, you would take the first letter of that and place it in your peg system. If there was already an image there, you would, as you say, do a quick walk down the aisle, or in mnemonic terms, create a story to link the stored items there.

So, let’s use a quick example to talk about. The best alphabetic peg system in my mind is the bestiary. So, it’s not a shopping center but a zoo for me. I like to play piano and enjoy Beethoven’s Für Elise and Chopin’s Funeral March. My F peg is a frog. The first piece is associated to the frog which is an image of fleas on a young girl kissing the frog. Then the story progresses from there in a tragic turn as the flea bites cause her death and her casket is carried down the street.

Now, instead of thinking of the pieces I know, I run through the bestiary. It helps to have that hash of the letter F to get to the right animal making it faster. Do I know how to play Chopin’s Fantaisie-Impromptu in C Minor? No, it’s not in my story at the frog peg.

I think that’s how hashing would be implemented in a mnemonic way. It seems to be a combination of the peg system and the story. I’m always open to other ideas. Hope that helped some.

3 Likes