# Given a file of „n‟ employee record with a set „k‟ of keys(4 digit) which uniquely determines the record in the file f. Assume that file f is maintained in memory by hash table(HT) of „m‟ memory locations with „L‟ as set of memory address(2 digit of location in HT). # Let the key in „k‟ and address in „L‟ are integers. Design and develop a program in C that uses hash function H:k->L and H(k)=kmod m(remainder method) and implement hashing technique to map a given key „k‟ to the address space L. Resolve the collision(if any) using LINEAR PROBING.

## Program :-

```#include<stdio.h> #include<stdlib.h> int L,max=5; void display() { int i; printf("\n Hash table contents are "); printf("\n Index\tdata\n"); for(i=0;i<max;i++) printf("\n%d\t%d\n",i,L[i]); } void linear_probe(int key,int num) { int i; if(L[key]==-1) L[key]=num; else { printf("\n Collision detected"); i=(key+1)%max; while(i!=key) { if(L[i]==-1) { L[i]=num; printf("\n Collision resolved through linear probe"); return; } i=(i+1)%max; } printf("\n Hash table is full"); display(); } } int main() { int i,num,key,input; for(i=0;i<max;i++) L[i]=-1; do { printf("\n Enter the number"); scanf("%d",&num); key=num%max; linear_probe(key,num); printf("\n Enter 1 to continue"); scanf("%d",&input); }while(input==1); display(); return 0; }```

Click to rate this post!
[Total: 0 Average: 0]

We will be happy to hear your thoughts Enable registration in settings - general