Friday, 8 April 2016

Week 12 SLOG - Hash

Its finally the end of the year! I really just want to be lazy and do nothing but I have to do this and study for exams.

In our last week we learned about Hash. Basically hash is a way to store references to objects with similar efficiency to a list but without having to allocate large amounts of adjacent memory. I think this is useful when we are using a computer that is storing many lists since each list requires large blocks of adjacent memory and thus memory is not assigned in the most efficient way.

Hashing can only be done on immutable objects since hashing is really just using an algorithm to convert the object into an index to store the object. Thus this algorithm must be consistent at the time of hashing and retrieval.

There is a big problem about hashing though, it is possible to have several objects assigned to the same index. This is called collision and happens a lot more common than it would seem intuitively. Professor Heap showed us that there is an abnormal amount of people with the same birthday when intuitively  it should require 365 people before a repeat.

We can solve this with one of two methods:
1. Probing: When we encounter an already filled hash index, we go find the next open one
2. Chaining: Keep a list called a bucket at each hash index.
The approach in this course is to use chaining.

One question I still have about hash is its relation to dictionaries. Are dictionaries hashes? Since we talked about how dictionaries are efficient.