The ones who are crazy enough to think they can change the world are the ones who do.- Steve Jobs
Hashing is a technique which can be understood from the real time application.
Assuming a class of 50 members, Each students has their Roll number in the range from 1 to 50. Now you the C Programmer collects all the students details using array from array[1] to array[50]. array[0] is neglected. Assuming a class of 50 members, Each students has their Roll number in the range from 1 to 50. Now you the C Programmer collects all the students details using array from array[1] to array[50]. array[0] is neglected. Now, assuming a next class of 50 members, Each students has their Roll number in the range from 101 to 150. Actual Programmer will initialize array[151] and waste the memory space from array[0] to array[100] and then collects all the students details from array[101] to array[150]. But you the C Programmer with more knowledge in data structure will divide every students roll no with 100 and then store the result from array[1] to array[50]. This technique is called as hashing.
Here is the C program to demonstrate Hashing.
#include <stdio.h> int main() { int arry[100], arry1[100], n, result = 0, i, count = 0; printf("Enter the size of an array : "); scanf("%d",&n); printf("\nEnter %d elements : \n",n); for(i = 0; i < n; i++) { scanf("%d",&arry[i]); } for(i = 0; i < n; i++) { result = arry[i] % 10; arry1[result] = arry[i]; printf("\nlocation = arry1[%d], value = %d ",result, arry1[result]); result = 0; } return 0; }
Enter the size of an array : 5 Enter 5 elements 101 102 103 104 105 location = arry1[1], value = 101 location = arry1[2], value = 102 location = arry1[3], value = 103 location = arry1[4], value = 104 location = arry1[5], value = 105
We may make mistakes(spelling, program bug, typing mistake and etc.), So we have this container to collect mistakes. We highly respect your findings.
© Copyright 2019