View on GitHub

reading-notes

HashTables

What is the meening of Hash?

Hash is to take a value “string” and using some algorithm to convert it in to another value, it is use for security or some other purpose, in Hash table it is using for determine the index of the array.

What is Buckets?

It is what is in an index of the array in Hash Table.

What is Collisions?

Keys Hashed to the same index in the Hash Table.

What is the HashTables?

Hashtable is a data structure use key-value pairs, each nood or bucket is a key value pair, Hashtable is use to quickly retrieve the value of the key. The location of the key depende of the Hash value of this key.

Big O of getting value from HashTable and Array:

Big O of getting value from Hashtable is 1.
Big O of getting value from array is n.

Hashing:

To get the location of the key => first convert all character to int, the some the output integer for all characters in the word and then * 599, and then % 1034

Key = "Cat"
Value = "Josie"

67 + 97 + 116 = 280

280 * 599 = 69648

69648 % 1024 = 16

Key gets placed in index of 16. 

What would happen if two different keys resolved to be the same index of the Hashtable?

Use Linkedlist to store multble values to the same key “in the same location”.

Internal Methods:

1- Add():

2- Find(): Check the location of the key by GetHash and then if the location is exist then search in side the likedlist for the value of this key.

3- Contains(): Check the location of the key by GetHash and then if the location is exist then search in side the likedlist for the key if exist return true