SlideShare a Scribd company logo
Experiment No. 10
Student Name: Vansh Garg UID: 21BCS4548
Branch: CSE (IOT) Section/Group: 21BIT-1 “A”
Semester: 3 Date of Performance: 04/11/2022
Subject Name: Data Structure Code: 21CSH-242
AIM:
Given a File of N employee records with a set K of Keys(4-digit) which uniquely determine the
records in file F. Assume that file F is maintained in memory by a Hash Table(HT) of m memory
locations with L as the set of memory addresses (2-digit) of locations in HT. Let the keys in K and
addresses in L are Integers. Design and develop a Program in C that uses Hash function H: K ®L as
H(K)=K mod 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.
Input/Apparatus Used:
Compiler used : X code for C – language
ALGORITHM:
Step 1: Start.
Step 2: Input the value of N nodes of the graph
Step 3: Create a graph of N nodes using adjacency matrix representation.
Step 3: Print the nodes reachable from the starting node using BFS.
Step 4: Check whether graph is connected or not using DFS.
Step 5: Stop.
PROGRAM CODE:
#include <stdio.h>
#include <stdlib.h>
#define MAX 10
struct employee
{
int id;
char name[15];
};
typedef struct employee EMP;
EMP emp[MAX];
int a[MAX];
int create(int num)
{
int key;
key = num;
return key;
}
int getemp(EMP emp[], int key)
{
printf("nEnter emp id: ");
scanf("%d", &emp[key].id);
printf("nEnter emp name: ");
scanf("%s",&emp[key].name);
return key;
}
void display()
{
int i, ch;
printf("n1.Display ALLn2.Filtered Display");
printf("nEnter the choice: ");
scanf("%d", &ch);
if (ch == 1)
{
printf("nThe hash table is:n");
printf("nHTKeytEmpIDtEmpName");
for (i = 0; i < MAX; i++)
printf("n%dt%dt%s", i, emp[i].id, emp[i].name);
}
else
{
printf("nThe hash table is:n");
printf("nHTKeytEmpIDtEmpName");
for (i = 0; i < MAX; i++)
if (a[i] != -1)
{
printf("n%dt%dt%s", i, emp[i].id, emp[i].name);
continue;
}
}
}
void linear_prob(int key, int num)
{
int flag, i, count = 0;
flag = 0;
if (a[key] == -1)
{
a[key] = getemp(emp, key);
}
else
{
printf("nCollision Detected...!!!n");
i = 0;
while (i < MAX)
{
if (a[i] != -1)
{
count++;
i++;}
else i++;
}
printf("nCollision avoided successfully using LINEAR PROBINGn");
if (count == MAX)
{
printf("n Hash table is full");
display();
exit(1);
}
else
{
getemp(emp, key + 1);
}
for (i = key; i < MAX; i++)
if (a[i] == -1)
{
a[i] = num;
flag = 1;
break;
}
i = 0;
while ((i < key) && (flag == 0))
{
if (a[i] == -1)
{
a[i] = num;
flag = 1;
break;
}
i++;
} // end while
} // end else
} // end linear_prob()
int main()
{int num, key, i;
int ans = 1;
printf("nCollision handling by linear probing: ");
for (i = 0; i < MAX; i++)
{a[i] = -1; }
do
{
printf("nEnter the data: ");
scanf("%d", &num);
key = create(num);
linear_prob(key, num);
printf("nDo you wish to continue? (1/0): ");
scanf("%d", &ans);
} while (ans);
display();}
OUTPUT:
nDo you wish to continue? (1/0): ");

More Related Content

Similar to ds-10.pdf

Create a C program which auto-completes suggestions when beginning t.pdf
Create a C program which auto-completes suggestions when beginning t.pdfCreate a C program which auto-completes suggestions when beginning t.pdf
Create a C program which auto-completes suggestions when beginning t.pdf
fedosys
 
solution-of-practicals-class-xii-comp.-sci.-083-2021-22 (1).pdf
solution-of-practicals-class-xii-comp.-sci.-083-2021-22 (1).pdfsolution-of-practicals-class-xii-comp.-sci.-083-2021-22 (1).pdf
solution-of-practicals-class-xii-comp.-sci.-083-2021-22 (1).pdf
parthp5150s
 
Chapter Eight(1)
Chapter Eight(1)Chapter Eight(1)
Chapter Eight(1)
bolovv
 

Similar to ds-10.pdf (20)

Create a C program which auto-completes suggestions when beginning t.pdf
Create a C program which auto-completes suggestions when beginning t.pdfCreate a C program which auto-completes suggestions when beginning t.pdf
Create a C program which auto-completes suggestions when beginning t.pdf
 
DSC program.pdf
DSC program.pdfDSC program.pdf
DSC program.pdf
 
Data Structure using C
Data Structure using CData Structure using C
Data Structure using C
 
String Manipulation Function and Header File Functions
String Manipulation Function and Header File FunctionsString Manipulation Function and Header File Functions
String Manipulation Function and Header File Functions
 
Ankita sharma focp
Ankita sharma focpAnkita sharma focp
Ankita sharma focp
 
solution-of-practicals-class-xii-comp.-sci.-083-2021-22 (1).pdf
solution-of-practicals-class-xii-comp.-sci.-083-2021-22 (1).pdfsolution-of-practicals-class-xii-comp.-sci.-083-2021-22 (1).pdf
solution-of-practicals-class-xii-comp.-sci.-083-2021-22 (1).pdf
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
 
CLISP Lab Manual - Dr.J.VijiPriya
CLISP Lab Manual - Dr.J.VijiPriyaCLISP Lab Manual - Dr.J.VijiPriya
CLISP Lab Manual - Dr.J.VijiPriya
 
Struct examples
Struct examplesStruct examples
Struct examples
 
ECE-PYTHON.docx
ECE-PYTHON.docxECE-PYTHON.docx
ECE-PYTHON.docx
 
7 functions
7  functions7  functions
7 functions
 
C file
C fileC file
C file
 
design and analysis of algorithm Lab files
design and analysis of algorithm Lab filesdesign and analysis of algorithm Lab files
design and analysis of algorithm Lab files
 
Chapter Eight(1)
Chapter Eight(1)Chapter Eight(1)
Chapter Eight(1)
 
Pushover analysis force analogy method with force control based on timoshenko...
Pushover analysis force analogy method with force control based on timoshenko...Pushover analysis force analogy method with force control based on timoshenko...
Pushover analysis force analogy method with force control based on timoshenko...
 
C Recursion, Pointers, Dynamic memory management
C Recursion, Pointers, Dynamic memory managementC Recursion, Pointers, Dynamic memory management
C Recursion, Pointers, Dynamic memory management
 
Basic C Programming Lab Practice
Basic C Programming Lab PracticeBasic C Programming Lab Practice
Basic C Programming Lab Practice
 
python_lab_manual_final (1).pdf
python_lab_manual_final (1).pdfpython_lab_manual_final (1).pdf
python_lab_manual_final (1).pdf
 
III MCS python lab (1).pdf
III MCS python lab (1).pdfIII MCS python lab (1).pdf
III MCS python lab (1).pdf
 
Final ds record
Final ds recordFinal ds record
Final ds record
 

Recently uploaded

CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
R&R Consult
 
Fruit shop management system project report.pdf
Fruit shop management system project report.pdfFruit shop management system project report.pdf
Fruit shop management system project report.pdf
Kamal Acharya
 
LIGA(E)11111111111111111111111111111111111111111.ppt
LIGA(E)11111111111111111111111111111111111111111.pptLIGA(E)11111111111111111111111111111111111111111.ppt
LIGA(E)11111111111111111111111111111111111111111.ppt
ssuser9bd3ba
 
Antenna efficency lecture course chapter 3.pdf
Antenna  efficency lecture course chapter 3.pdfAntenna  efficency lecture course chapter 3.pdf
Antenna efficency lecture course chapter 3.pdf
AbrahamGadissa
 
Standard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - NeometrixStandard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - Neometrix
Neometrix_Engineering_Pvt_Ltd
 

Recently uploaded (20)

Final project report on grocery store management system..pdf
Final project report on grocery store management system..pdfFinal project report on grocery store management system..pdf
Final project report on grocery store management system..pdf
 
Explosives Industry manufacturing process.pdf
Explosives Industry manufacturing process.pdfExplosives Industry manufacturing process.pdf
Explosives Industry manufacturing process.pdf
 
HYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generationHYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generation
 
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
 
Fruit shop management system project report.pdf
Fruit shop management system project report.pdfFruit shop management system project report.pdf
Fruit shop management system project report.pdf
 
Natalia Rutkowska - BIM School Course in Kraków
Natalia Rutkowska - BIM School Course in KrakówNatalia Rutkowska - BIM School Course in Kraków
Natalia Rutkowska - BIM School Course in Kraków
 
LIGA(E)11111111111111111111111111111111111111111.ppt
LIGA(E)11111111111111111111111111111111111111111.pptLIGA(E)11111111111111111111111111111111111111111.ppt
LIGA(E)11111111111111111111111111111111111111111.ppt
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
 
The Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfThe Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdf
 
Antenna efficency lecture course chapter 3.pdf
Antenna  efficency lecture course chapter 3.pdfAntenna  efficency lecture course chapter 3.pdf
Antenna efficency lecture course chapter 3.pdf
 
ASME IX(9) 2007 Full Version .pdf
ASME IX(9)  2007 Full Version       .pdfASME IX(9)  2007 Full Version       .pdf
ASME IX(9) 2007 Full Version .pdf
 
shape functions of 1D and 2 D rectangular elements.pptx
shape functions of 1D and 2 D rectangular elements.pptxshape functions of 1D and 2 D rectangular elements.pptx
shape functions of 1D and 2 D rectangular elements.pptx
 
Toll tax management system project report..pdf
Toll tax management system project report..pdfToll tax management system project report..pdf
Toll tax management system project report..pdf
 
Standard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - NeometrixStandard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - Neometrix
 
Courier management system project report.pdf
Courier management system project report.pdfCourier management system project report.pdf
Courier management system project report.pdf
 
İTÜ CAD and Reverse Engineering Workshop
İTÜ CAD and Reverse Engineering WorkshopİTÜ CAD and Reverse Engineering Workshop
İTÜ CAD and Reverse Engineering Workshop
 
Architectural Portfolio Sean Lockwood
Architectural Portfolio Sean LockwoodArchitectural Portfolio Sean Lockwood
Architectural Portfolio Sean Lockwood
 
Cloud-Computing_CSE311_Computer-Networking CSE GUB BD - Shahidul.pptx
Cloud-Computing_CSE311_Computer-Networking CSE GUB BD - Shahidul.pptxCloud-Computing_CSE311_Computer-Networking CSE GUB BD - Shahidul.pptx
Cloud-Computing_CSE311_Computer-Networking CSE GUB BD - Shahidul.pptx
 
fluid mechanics gate notes . gate all pyqs answer
fluid mechanics gate notes . gate all pyqs answerfluid mechanics gate notes . gate all pyqs answer
fluid mechanics gate notes . gate all pyqs answer
 

ds-10.pdf

  • 1. Experiment No. 10 Student Name: Vansh Garg UID: 21BCS4548 Branch: CSE (IOT) Section/Group: 21BIT-1 “A” Semester: 3 Date of Performance: 04/11/2022 Subject Name: Data Structure Code: 21CSH-242 AIM: Given a File of N employee records with a set K of Keys(4-digit) which uniquely determine the records in file F. Assume that file F is maintained in memory by a Hash Table(HT) of m memory locations with L as the set of memory addresses (2-digit) of locations in HT. Let the keys in K and addresses in L are Integers. Design and develop a Program in C that uses Hash function H: K ®L as H(K)=K mod 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. Input/Apparatus Used: Compiler used : X code for C – language ALGORITHM: Step 1: Start. Step 2: Input the value of N nodes of the graph Step 3: Create a graph of N nodes using adjacency matrix representation. Step 3: Print the nodes reachable from the starting node using BFS. Step 4: Check whether graph is connected or not using DFS. Step 5: Stop. PROGRAM CODE: #include <stdio.h> #include <stdlib.h> #define MAX 10 struct employee { int id; char name[15]; }; typedef struct employee EMP; EMP emp[MAX]; int a[MAX]; int create(int num) { int key; key = num;
  • 2. return key; } int getemp(EMP emp[], int key) { printf("nEnter emp id: "); scanf("%d", &emp[key].id); printf("nEnter emp name: "); scanf("%s",&emp[key].name); return key; } void display() { int i, ch; printf("n1.Display ALLn2.Filtered Display"); printf("nEnter the choice: "); scanf("%d", &ch); if (ch == 1) { printf("nThe hash table is:n"); printf("nHTKeytEmpIDtEmpName"); for (i = 0; i < MAX; i++) printf("n%dt%dt%s", i, emp[i].id, emp[i].name); } else { printf("nThe hash table is:n"); printf("nHTKeytEmpIDtEmpName"); for (i = 0; i < MAX; i++) if (a[i] != -1) { printf("n%dt%dt%s", i, emp[i].id, emp[i].name); continue; } } } void linear_prob(int key, int num) { int flag, i, count = 0; flag = 0; if (a[key] == -1) { a[key] = getemp(emp, key); } else { printf("nCollision Detected...!!!n"); i = 0; while (i < MAX)
  • 3. { if (a[i] != -1) { count++; i++;} else i++; } printf("nCollision avoided successfully using LINEAR PROBINGn"); if (count == MAX) { printf("n Hash table is full"); display(); exit(1); } else { getemp(emp, key + 1); } for (i = key; i < MAX; i++) if (a[i] == -1) { a[i] = num; flag = 1; break; } i = 0; while ((i < key) && (flag == 0)) { if (a[i] == -1) { a[i] = num; flag = 1; break; } i++; } // end while } // end else } // end linear_prob() int main() {int num, key, i; int ans = 1; printf("nCollision handling by linear probing: "); for (i = 0; i < MAX; i++) {a[i] = -1; } do { printf("nEnter the data: ");
  • 4. scanf("%d", &num); key = create(num); linear_prob(key, num); printf("nDo you wish to continue? (1/0): "); scanf("%d", &ans); } while (ans); display();} OUTPUT: nDo you wish to continue? (1/0): ");