HASHING TECHNIQUES
To implement hashing using Open Addressing
ALGORITHM:
Step 1: Get the Hash Size
Step 2: Get the element to placed inside the Hash Table perform open hashing place the element in the
particular position chain
Step 3: If the element is already in particular index, find next Empty Space
Step 4: If index is HashSize-1 then Index becomes 0.
Step 5: Continue step-2 till the user request otherwise exit from the process.
PROGRAM:
#include <stdio.h> #include <conio.h> #define HSIZE 7 void main() { int key[10],H[HSIZE]={0,0,0,0,0,0,0},hash[10],hash1,i,j,n; clrscr(); printf("Enter no of elements:\n"); scanf("%d",&n); printf("Enter Key values:\n"); for(j=0;j<n;j++) { scanf("%d",&key[j]); } printf("output:\n"); printf("Index\t\tHashtablevalue:\n"); printf("------------------------:\n"); for(j=0;j<n;j++) { hash[j]=key[j]%HSIZE; hash1=hash[j]; printf("Index=%d\n",hash1); if(H[hash1]==0) { H[hash1]=key[j]; } else { if(hash1==HSIZE-1) hash1=0; for(i=hash1;i<HSIZE;i++) { if(H[i]==0) { H[i]=key[j]; break; } } } } for(i=0;i<HSIZE;i++) { printf("%d\t\t%d\n",i,H[i]); } getch(); } OUTPUT Enter no of elements: 5 Enter Key values: 18 72 65 34 13 Index Hashtablevalue: ------------------------: Index=4 Index=2 Index=2 Index=6 Index=6 0 13 1 0 2 72 3 65 4 18 5 0 6 34