0% found this document useful (0 votes)
30 views2 pages

Quadratic Pro

The document describes a program that implements quadratic probing to resolve collisions in a hash table. The program defines functions for initializing the hash table, inserting elements, searching for elements, and displaying the table contents. It demonstrates inserting multiple elements and searching for an element in the hash table using quadratic probing.

Uploaded by

Aswith Reddy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views2 pages

Quadratic Pro

The document describes a program that implements quadratic probing to resolve collisions in a hash table. The program defines functions for initializing the hash table, inserting elements, searching for elements, and displaying the table contents. It demonstrates inserting multiple elements and searching for an element in the hash table using quadratic probing.

Uploaded by

Aswith Reddy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

//QUADRATIC PROBING#include <stdio.

h>
#define size 10
struct hash
{
int hkey,key;
}ht[size];
void insert()
{
int ele,index;
printf("eneter the key");
scanf("%d",&ele);
index=ele%size;
if(ht[index].key==-1)
ht[index].key=ele;
else
{
for(int j=1;j<size;j++)
{
int t=(index+j*j)%size;
if(ht[t].key==-1)
{
ht[t].key=ele;
break;
}
}
}
}
void search()
{
int ele,index,j,flag=0;
printf("enter the key value to search\n");
scanf("%d",&ele);
index=ele%size;
if(ht[index].key==ele)
printf("key is found at index %d\n",index);
else
{
for(int j=1;j<size;j++)
{
int t=(index+j*j)%size;
if(ht[t].key==ele)
{flag=1;
break;
}
}
}
if(flag==1)
printf("key value found at index %d=\n",j);
else
printf("key not found\n");
}
void initially()
{
int i;
for(i=0;i<size;i++)
{
ht[i].key=-1;
ht[i].hkey=i;
}
}
void display()
{
for(int i=0;i<size;i++)
printf("hash_table[%d]=%d\n",ht[i].hkey,ht[i].key);
}
int main() {

initially();
insert();
insert();
insert();
insert();
display();
return 0;
}

You might also like