Sorting – Address Calculation Sort (Hashing)

The result of this function determines into which of the several subfiles the record is to be placed.

The function should have the property that: if x <= y , f (x) <= f (y), Such a function is called order preserving.

An item is placed into a subfile in correct sequence by placing sorting method – simple insertion is often used.

Example:

25 57 48 37 12 92 86 33

Let us create 10 subfiles. Initially each of these subfiles is empty. An array of pointer f(10) is declared, where f(i) refers to the first element in the file, whose first digit is i. The number is passed to hash function, which returns its last digit (ten’s place digit), which is placed at that position only, in the array of pointers.

Thus it is inserted in 3rd subfile (4th) only, but must be checked with the existing elements for its proper position in this subfile.

Arrangement of nodes in subfiles

Efficiency: If all the elements (n) are uniformly distributed over m subfiles then n/m is approximately 1, time of the sort is near O(n).

On the other hand if maximum elements accommodate in one or two subfiles, then n/m is much larger significant work is required to insert its proper subfile at its proper position and efficiency is O(n2).