Before continuing this topic you must know about Hashing and Collision. We discussed collision in the Division Modulo Method of Hashing.

Let us begin with the Mid Square method, In this method, HashFunction will find the square of the given element then took the middle digits and use those digits as the index of the element. Let's understand with an example.

Example:
Suppose the size of the Hash Table (m) = 10 (0 - 9) maximum digits required for the index is 1
Element (x) = 12  ⇒ x2 = 144
Mid 1 digit of 144 is 4, so the element x=12 will be stored at the index=4 in the hash table with the size of 10 slots.

Another Example:
Suppose the size of the Hash Table (m) = 1000 (0 - 999) maximum digits required for the index is 3
Element (x) = 87431  ⇒ x2 = 7644179761
The possible 3 digit mids of 7644179761  are 417 or 179, we can pick any of those mids. If we pick 419 then the element x=87431  will be stored at the index=419 in the hash table with the size of 1000 slots.

Note: In the case of two mids, we have to remember that if pick the left side mid then during searching for the same element or inserting more elements, we must pick the left mid.

There are very less chances of collision in this method.