ASSIGNMENT 14 CS 392 : TCPTUTOR

0
73

PROBLEM STATEMENT

Write a C program to implement Linear probing Hash functions. Resolve collision by any collision resolution technique.

ALGORITHM

Algorithm for hashing of an array of integer elements:

i:temporary variable for loop
n:temporary variable
d: array of initial elements which are to be hashed
e: array which will be formed after hashing
M:size of array or no. of elements in array to be hashed

Step 1: SET i=0
Step 2: SET n=d[i]%M
SET n=(n+1)%M while e[n]!= -1
[End of inner loop]
SET e[n]=i
Step 3: Repeat step 2 while i<M
[End of outer loop]
Step 4: EXIT

SOURCE CODE

#include<stdio.h>
#include<conio.h>
int main()
{
int i,n,m=5;
int a[]={12435,72476,26473,73490,54858};
int b[]={-1,-1,-1,-1,-1};
for(i=0;i<m;i++)
{
n=a[i]%m;
while(b[n]!=-1)
n=(n+1)%m;
b[n]=i;
}
for(i=0;i<m;i++)
printf(“%d\n”,b[i]);
return(0);
}

OUTPUT

0
1
3
2
4
*****************************

LEAVE A REPLY

Please enter your comment!
Please enter your name here