Skip to main content

Hashing & Hash Table


Hashing & Hash Table

Hashing is a technique used to access value in database or array faster.
The way hashing works is the original string of characters are transformed in to short length value or key called Hash Key, that represent the original string or as index to access original value stored in array called Hash Table or database.
The way to hash a string is called Hash Function. There is some important methods to construct hash function :
·       Mid-square
square the string / identifier and extract the middle r bits of the result.





·       Division ( most common )
Divide the string /identifier using modulus operator by value M (can be any value but usually prime number, table size or the size of memory used.






·       Folding
Divide each value into number of part with the same number of digits. Sum all of the part. If there is last carry in hash value, the last carry will be ignored.








·       Digit Extraction
Predefined digit of the give number is considered as the hash address. Ex: if x =14568, we exteact 1st, 3rd, and 5th digit, and the has code of 158
·       Rotating Hash
Use hash method, after get the hash address/key, rotate the address by shifting the digit to get new hash address/key.

Collision

is when the different string have the exact same hash address. If this thing happens there is  2 general way to handle this:
-          Linear Probing : search the next empt slot and put the string there
-          Chainin             : put the string in a slot as a chained link ( linked list).


Implementation of Hash Table in Block Chain

The data in Hash Table is divided and stored in the different node, while in the block chain the data is saved like the hash Table but the data is not divided in blockchain, in blockchain all node have the copy of all the data. As far as i can find, hash table is not used in Block Chain.



Comments

Popular posts from this blog

AVL & B Tree

AVL TREE AVL TREE is balance binary search tree, so the difference height of left subtree and right subtree is 0 or 1. 4 case of unbalance: ·        Case 1 : (L-L) the deepest node is located at the left sub tree of the left child of T. ·        Case 2 : (L-R) the deepest node is located at the right sub tree of the right child of T. ·        Case 3 : (R-L) the deepest node is located at the right sub tree of the left child of T. ·        Case 4 : (L-R) the deepest node is located at the left sub tree of the right child of T. Inserting and Deleting in AVL Tree is the same as normal Binary tree but if the tree is not balance after insert or delete we need to rebalance it. Rebalance AVL TREE ·   Single Rotation Case 1 & 2 ·   Double Rotation to fix case 3 & 4 Example for fixing case 3: ...