Thursday, April 7, 2016

Entry 11: Week 12: The End...?

This is probably my last post on this sLOG. Maybe if I remember I'll update once more after the exam or when I receive my final mark.

Supposedly this week's topic is on hash tables. I must admit that because it's near final seasons I started blanking out a bit during the lectures. It's quite horrible since I hadn't encountered hash tables before. *sigh*

Anyways. Hash tables are a much more efficient data structure as compared to lists and whatnot. It makes up the basis for sets and dictionaries. They have a special run time efficiency for fetching the data inside them -- O(1). Very ideal. How? Similar to how a list can retrieve data almost immediately when given a specific index, Hash Tables put a specific index (hashes?) the objects that are put in them. For example, a simple hashing function is to convert the data into some sort of integer and use the int%capacity. The data will be essentially assigned an unique id. Upon on retrieval, the data will use its specific "key" to find the corresponding storage position in the hash table.

So of course, two items that may have the same key must be considered -- there are usually two methods to deal with this:
1. Probing: exploring in a systematic way to find the next empty position such that eventually all positions of the hash table will be visited once if there were no empty spots.
2. Chaining: keep a small list at each "bucket" of the hash table - append the conflicting elements in the small list and retrieve from it.
Our course focuses more on chaining and uses it in the code, although it was said during class that both methods work well for hash tables.