Closed Hashing 

                          With

            Linear Probing using ‘C

Direct testing is a crash goal method utilized in hash tables to deal with impacts when two keys guide to a similar file. Hash tables are information structures that store key-esteem coordinates, and hash capabilities are utilized to plan keys to cluster lists for proficient recovery, inclusion, and cancellation activities.


At the point when an impact happens with direct examining, rather than putting away the impacted keys in discrete chains like in open hashing, the following accessible (vacant) space in the hash table is looked straightly until an unfilled opening is found. The thought is to test the following continuous space until an unfilled opening is found or the whole table has been crossed.


Here is a bit by bit clarification of how direct examining functions during inclusion and search tasks:


1. Inclusion:


·        Figure the hash worth of the key utilizing the hash capability.


·        Assuming the determined file is vacant (void), store the key-esteem pair in that space.


·        On the off chance that the determined file is involved, test the following opening directly until a vacant space is found.


·        Embed the key-esteem pair in the main void space experienced.


2. Search:


·        Figure the hash worth of the key utilizing the hash capability.


·        Begin looking for the key from the determined file.


·        In the event that the key is found at the determined record, return the relating esteem.


·        On the off chance that the key isn't found at the determined record, test the following space straightly until the key is found or an unfilled opening is experienced.


·        In the event that an unfilled opening is experienced during the straight testing, it implies the key is absent in the hash table.


It's critical to take note of that while utilizing straight testing, the essential bunching issue can emerge. Essential grouping alludes to the propensity of keys that crash to bunch together in continuous spaces. This can bring about longer hunt times and decreased execution, particularly as the heap factor (normal number of keys per space) increments.


To moderate essential grouping, procedures like twofold hashing or quadratic examining can be utilized as elective crash goal strategies.


Generally, direct examining is a basic and ordinarily utilized crash goal procedure where impacted keys are put away in the following accessible opening, considering proficient key-esteem recovery and inclusion in hash tables.

 

Program:-

#include<stdio.h>

//#include<conio.h>

const int  capacity=10;

 

 

int main()

{

int i,x,arr[capacity];

 

 

for(i=0;i<capacity;i++)

arr[i]=-1;

 

printf("enter how many elements u want enter\n");

printf("no of elements must less or equal to capacity\n");

scanf("%d",&x);

 

for(i=0;i<x;i++)

{

 

 insert(arr);

}

 

for(i=0;i<capacity;i++)

printf("%d:%d\n",i,arr[i]);

return 0;

}

 

int insert(int arr[])

{

int key,index,size;

printf("enter the key ");

scanf("%d",&key);

size=key;

 

index=key % capacity;

while(arr[index]!=-1)

{

key++;

index=key%capacity;

}

if(arr[index]==-1)

arr[index]=size;

return 0;

 

}

Output:-