Professional Documents
Culture Documents
Practical 1
Practical 1
Problem Statement :- Consider telephone book database of N clients. Make use of a hash
table implementation to quickly look up client‘s telephone number. Make use of two collision
handling techniques and compare them using number of comparisons required to find a set of
telephone numbers
Theory Concept:- Hash table is one of the most important data structures that uses a special
function known as a hash function that maps a given value with a key to access the elements
faster.
A Hash table is a data structure that stores some information, and the information has
basically two main components, i.e., key and value. The hash table can be implemented with
the help of an associative array. The efficiency of mapping depends upon the efficiency of the
hash function used for mapping.
Program:
#include<iostream>
#include<string.h>
struct node
int value;
node* next;
}*HashTable[10];
class hashing
public:
hashing()
{ HashTable[i]=NULL;
}
int HashFunction(int value)
return (value%10);
node* create_node(int x)
temp->next=NULL;
temp->value=x;
return temp;
void display()
temp=HashTable[i];
cout<<"a["<<i<<"] : ";
while(temp !=NULL)
cout<<" ->"<<temp->value;
temp=temp->next;
cout<<"\n";
} }
{
if (entry->value==value)
cout<<hash_val<<" : "<<entry->value<<endl;
flag = true;
entry = entry->next;
if (!flag)
return -1;
if (entry == NULL )
return;
if(entry->value==value)
HashTable[hash_val]=entry->next;
return;
entry = entry->next;
entry->next=(entry->next)->next;
head = create_node(value);
temp=HashTable[hash_val];
if (temp == NULL)
HashTable[hash_val] =head;
else
temp = temp->next;
temp->next =head;
};
int main()
int ch;
int data,search,del;
hashing h;
do
cin>>ch;
switch(ch)
cin>>data;
h.insertElement(data);
break;
case 2:h.display();
break;
cin>>search;
if (h.searchElement(search) == -1)
continue;
break;
cin>>del;
h.deleteElement(del);
cout<<"Phno. Deleted"<<endl;
break;
}while(ch!=5);
return 0;
Output : -
Conclusion: - Thus we have implemented hash table to quickly look up client‘s telephone
number.