data structures lab manual
data structures lab manual
Name: ……………………………………………………..….
Branch: ………………………………………………….……
USN: ……………………………….……………………….…
PREFACE
Mission
M1: Developing practically trained skilled professionals to meet the demands of the
corporate world.
M2: Creating an ecosystem of academic excellence through the best teaching-learning
methods.
M3: Grooming professionals with high ethical values and ability to solve real-life problems
PEO2: Graduates will be able to analyse and understand current pedagogical techniques,
industry accepted computing practices and state-of-art technology to deliver solutions by
creative intuitions towards technological growth and societal needs.
PEO3: Graduates will be able to exhibit cultural awareness, teamwork with professional
i
ethics, effective communication skills and leader qualities to achieve higher career goals.
PEO4: Graduates will be able to pursue higher education in pursuit of lifelong learning and
explore the research possibilities, entrepreneurship opportunities and novel innovation
practices.
PSO2: Identify the various analysis & design methodologies for facilitating development of
effective algorithms and code for high quality system software products with focus on
performance optimization.
ii
PROGRAM OUTCOMES (POs)
iii
8. Ethics: Apply ethical principles and commit to professional ethics and
responsibilities and norms of the engineering practice.
9. Individual and team work: Function effectively as an individual, and as
a member or leader in diverse teams, and in multidisciplinary settings.
iv
INDEX
Sl.No Contents Page No
v
Implementation of Queue with maximum size MAX)
a. Insert an Element on to Circular QUEUE
b. Delete an Element from Circular QUEUE
c. Demonstrate Overflow and Underflow situations on Circular
QUEUE
d. Display the status of Circular QUEUE
e. Exit Support the program with appropriate functions for each
of the above operations
8 Develop a menu driven Program in C for the following 30
operations on Singly Linked List (SLL) of Student Data with
the fields: USN, Name, Programme, Sem, PhNo
a. Create a SLL of N Students Data by using front insertion.
b. Display the status of SLL and count the number of nodes in
it
c. Perform Insertion / Deletion at End of SLL
d. Perform Insertion / Deletion at Front of SLL(Demonstration
of stack)
e. Exit
9 Develop a menu driven Program in C for the following 40
operations on Doubly Linked List (DLL) of Employee Data
with the fields: SSN, Name, Dept, Designation, Sal, PhNo
a. Create a DLL of N Employees Data by using end insertion.
b. Display the status of DLL and count the number of nodes in
it
c. Perform Insertion and Deletion at End of DLL
d. Perform Insertion and Deletion at Front of DLL
e. Demonstrate how this DLL can be used as Double Ended
Queue.
f. Exit
10 Develop a Program in C for the following operationson Singly 51
Circular Linked List (SCLL) with header nodes a. Represent
and Evaluate
a Polynomial P(x,y,z) = 6x2y2z-4yz5 +3x2yz+2xy5z-2xyz3
b. Find the sum of two polynomials POLY1(x,y,z) and
POLY2(x,y,z) and store the result in POLYSUM(x,y,z)
Support the program with appropriate functions for each of the
above operations
11 Develop a menu driven Program in C for the following 61
operations on Binary Search Tree (BST) of Integers .
a. Create a BST of N Integers: 6, 9, 5, 2, 8, 15, 24, 14, 7, 8, 5, 2
b. Traverse the BST in Inorder, Preorder and Post Order
c. Search the BST for a given element (KEY) and report the
appropriate message
d. Exit
vi
12 Develop a Program in C for the following operations on 70
Graph(G) of Cities a. Create a Graph of N cities using
Adjacency Matrix.
b. Print all the nodes reachable from a given starting node in a
digraph using DFS/BFS method
13 Given a File of N employee records with a set K of Keys (4- 74
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. 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.
14 Appendix A 77
15 Appendix B 80
Laboratory Outcomes:
The student should be able to:
● Analyze various linear and non-linear data structures.
● Demonstrate the working nature of different types of data structures and their
applications
● Use appropriate searching and sorting algorithms for the given scenario.
● Apply the appropriate data structure for solving real world problems.
vii
○ For laboratories having PART A and PART B
■ Part A – Procedure + Execution + Viva = 6 + 28 + 6 = 40 Marks
■ Part B – Procedure + Execution + Viva = 9 + 42 + 9 = 60 Marks
Course objectives:
CO2 Demonstrate the working nature of different types of data structures and
their applications
CO3 Use appropriate searching and sorting algorithms for the give scenario.
CO4 Apply the appropriate data structure for solving real world problems
PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO1 PO12
1
CO1 3 - 3 - - - - - - - - -
CO2 2 2 3 - - - - - - - - -
CO3 2 2 3 - - - - - - - - -
CO4 - - - - - - - - 2 2 - -
viii
LABORATORY RUBRICS
Sl No Description Marks
1 Continuous Evaluation 30
c. Viva voice 5
d. Record write up 10
2 Internal Test 20
ix
Program 1:
Develop a Program in C for the following:
a) Declare a calendar as an array of 7 elements (A dynamically Created array) to represent 7 days of a
week. Each Element of the array is a structure having three fields. The first field is the name of the
Day (A dynamically allocated String), The second field is the date of the Day (A integer), the third field
is the description of the activity for a particular day (A dynamically allocated String).
b) Write functions create(), read() and display(); to create the calendar, to read the data from the
keyboard and to print weeks activity details report on screen.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main() {
printf("Creating a calendar:\n");
create();
return 0;
}
Output:
Creating a calendar:
Enter the name of day 1: Monday
Enter the date of day 1: 30
Enter the activity for day 1: 3rd Sem starts
Enter the name of day 2: Tuesday
Enter the date of day 2: 31
Enter the activity for day 2: Interaction with juniors
Enter the name of day 3: Wednesday
Enter the date of day 3: 1
Enter the activity for day 3: Kannada Rajyotsava
Enter the name of day 4: Thursday
Enter the date of day 4: 2
Develop a Program in C for the following operations on Strings. a. Read a main String (STR), a Pattern
String (PAT) and a Replace String (REP) b. Perform Pattern Matching Operation: Find and Replace
all occurrences of PAT in STR with REP if PAT exists in STR. Report suitable messages in case PAT
does not exist in STR Support the program with functions for each of the above operations. Don't use
Built-in functions.
#include<stdio.h>
char str[50], pat[20], rep[20], ans[50];
int c=0, m=0, i=0, j=0, k, flag=0;
void stringmatch()
{
while(str[c] !='\0')
{
if(str[m] == pat[i])
{
i++;
m++;
if(pat[i] == '\0')
{
flag = 1;
for(k=0; rep[k]!='\0'; k++, j++)
{
ans[j] = rep[k];
}
i = 0;
c = m;
}
}
else
{
ans[j]= str[c];
Output:
Enter the main string: Welcome to BGSgroups
Enter the pat string: groups
Enter the replace string: CET
Resultant string is Welcome to BGSCET
Develop a menu driven Program in C for the following operations on STACK of Integers (Array
Implementation of Stack with maximum size MAX)
#include<stdio.h>
#include<stdlib.h>
#define MAX 5
int s[MAX];
int top = -1;
void push(int item);
int pop();
void palindrome();
void display();
void main()
{
int choice, item;
while(1)
{
printf("\n\n\n\n~~~~~~Menu~~~~~~ : ");
printf("\n=>1.Push an Element to Stack and Overflow demo ");
printf("\n=>2.Pop an Element from Stack and Underflow demo");
printf("\n=>3.Palindrome demo ");
printf("\n=>4.Display ");
printf("\n=>5.Exit");
printf("\nEnter your choice: ");
top = top + 1 ;
int pop()
{
int item;
if(top == -1)
{
printf("\n~~~~Stack underflow~~~~");
return -1;
}
item = s[top];
top = top - 1;
return item;
}
void display()
{
int i;
if(top == -1)
{
printf("\n~~~~Stack is empty~~~~");
return;
}
printf("\nStack elements are:\n ");
for(i=top; i>=0 ; i--)
printf("| %d |\n", s[i]);
}
void palindrome()
{
~~~~~~Menu~~~~~~ :
=>1.Push an Element to Stack and Overflow demo
=>2.Pop an Element from Stack and Underflow demo
=>3.Palindrome demo
=>4.Display
=>5.Exit
Enter your choice: 1
~~~~~~Menu~~~~~~ :
=>1.Push an Element to Stack and Overflow demo
=>2.Pop an Element from Stack and Underflow demo
=>3.Palindrome demo
=>4.Display
=>5.Exit
~~~~~~Menu~~~~~~ :
=>1.Push an Element to Stack and Overflow demo
=>2.Pop an Element from Stack and Underflow demo
=>3.Palindrome demo
=>4.Display
=>5.Exit
Enter your choice: 1
~~~~~~Menu~~~~~~ :
=>1.Push an Element to Stack and Overflow demo
=>2.Pop an Element from Stack and Underflow demo
=>3.Palindrome demo
=>4.Display
=>5.Exit
Enter your choice: 4
~~~~~~Menu~~~~~~ :
=>1.Push an Element to Stack and Overflow demo
=>2.Pop an Element from Stack and Underflow demo
=>3.Palindrome demo
=>4.Display
=>5.Exit
Enter your choice: 4
~~~~~~Menu~~~~~~ :
=>1.Push an Element to Stack and Overflow demo
~~~~~~Menu~~~~~~ :
=>1.Push an Element to Stack and Overflow demo
=>2.Pop an Element from Stack and Underflow demo
=>3.Palindrome demo
=>4.Display
=>5.Exit
Enter your choice: 5
Output 2:
~~~~~~Menu~~~~~~ :
~~~~~~Menu~~~~~~ :
=>1.Push an Element to Stack and Overflow demo
=>2.Pop an Element from Stack and Underflow demo
=>3.Palindrome demo
=>4.Display
=>5.Exit
Enter your choice: 1
~~~~~~Menu~~~~~~ :
=>1.Push an Element to Stack and Overflow demo
=>2.Pop an Element from Stack and Underflow demo
=>3.Palindrome demo
=>4.Display
=>5.Exit
Enter your choice: 1
~~~~~~Menu~~~~~~ :
=>1.Push an Element to Stack and Overflow demo
=>2.Pop an Element from Stack and Underflow demo
=>3.Palindrome demo
=>4.Display
=>5.Exit
Enter your choice: 3
It is palindrome number
~~~~~~Menu~~~~~~ :
=>1.Push an Element to Stack and Overflow demo
=>2.Pop an Element from Stack and Underflow demo
=>3.Palindrome demo
=>4.Display
=>5.Exit
Enter your choice: 5
#include <ctype.h>
#include <stdio.h>
Output 2:
enter the Infix Expression : a+(b-c)*d/e^f
Given Infix Expn is: a+(b-c)*d/e^f
The Postfix Expn is:abc-d*ef^
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int pop()
{
int item;
item = s[top];
top = top-1;
return item;
}
void main()
{
printf("\nEnter a valid postfix expression:\n");
scanf("%s", postfix);
Output:
Enter a valid postfix expression:
651-4*23$/+
Result = 8
Output 2:
Enter a valid postfix expression:
861-*2/32^%
Result = 2
#include<stdio.h>
#include<conio.h> int count=0,n;
int tower(int n,char s,char t,char d)
{
if(n==1)
{
printf("\n Move disc 1 from %c to %c",s,d); count++;
return 1;
}
tower(n-1,s,d,t);
printf("\n Move disc %d from %c to %c",n,s,d); count++;
tower(n-1,t,s,d);
}
int main( )
Output 1:
Enter the no. of discs:2
Output 2:
Enter the no. of discs:4
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#define SIZE 5
int q[SIZE], i, r=-1, f=0, option, count=0, j;
int main( )
{
for(;;)
{
printf("\n 1.Insert 2.Delete\n 3.Display 4.Exit");
printf("\nEnter your option:");
scanf("%d",&option);
switch(option)
{
case 1: //Inserting items to Queue
if(count==SIZE)
printf("\n Q is Full\n");
else
{
r=(r+1)%SIZE;
printf("\nEnter the item:");
scanf("%d",&q[r]);
count++;
}
break;
Output:
1.Insert 2.Delete
3.Display 4.Exit
1.Insert 2.Delete
3.Display 4.Exit
Enter your option:1
1.Insert 2.Delete
3.Display 4.Exit
Enter your option:1
1.Insert 2.Delete
3.Display 4.Exit
Enter your option:1
1.Insert 2.Delete
3.Display 4.Exit
Enter your option:1
Q is Full
1.Insert 2.Delete
3.Display 4.Exit
Enter your option:3
10 20 30 40 50
1.Insert 2.Delete
3.Display 4.Exit
Enter your option:2
1.Insert 2.Delete
3.Display 4.Exit
Enter your option:2
Q is empty
struct node
{
char usn[11];
char name[25];
int sem;
char branch[5];
unsigned long long phno;
struct node *next;
};
typedef struct node NODE;
Output
List Operations
===============
1.Create List of n students by using front Insert
2.Display the status and count the nodes
3.Perform Insertion and Deletion at End of SLL
4.Perform Insertion and Deletion at Front of SLL
5.Exit
Enter your choice : 1
Enter the number of students
2
List Operations
===============
1.Create List of n students by using front Insert
2.Display the status and count the nodes
3.Perform Insertion and Deletion at End of SLL
4.Perform Insertion and Deletion at Front of SLL
5.Exit
Enter your choice : 3
1. Insert at End and 2 Delete From End=1
Enter USN: 1mp22ec003
Enter Name : asha
Enter Branch: ec
Enter Sem:3
Enter Phone no : 8976543218
List Operations
===============
1.Create List of n students by using front Insert
2.Display the status and count the nodes
3.Perform Insertion and Deletion at End of SLL
4.Perform Insertion and Deletion at Front of SLL
List Operations
===============
1.Create List of n students by using front Insert
2.Display the status and count the nodes
3.Perform Insertion and Deletion at End of SLL
4.Perform Insertion and Deletion at Front of SLL
5.Exit
Enter your choice : 2
Node Count=3 & Elements in the list are :
USN Name Brh Sem Phone
1mp22cs002 abhishek cse 3 9876543213
1mp22is001 aishwarya ise 3 8765432192
1mp22ec003 asha ec 3 8976543218
List Operations
===============
1.Create List of n students by using front Insert
2.Display the status and count the nodes
3.Perform Insertion and Deletion at End of SLL
4.Perform Insertion and Deletion at Front of SLL
5.Exit
Enter your choice : 4
1. Insert at Front and 2.Delete From Front=2
Deleted Node is:
1mp22cs002 abhishek cse 3 9876543213
#include<stdio.h>
#include<stdlib.h>
#include<string.h> struct employee
{
char ssn[11];
char name[21];
char dept[15];
char design[15];
int salary;
unsigned long long phno;
};
typedef struct employee EMP; struct node
{
char ssn[11];
char name[21];
char dept[15];
char design[15];
int salary;
unsigned long long phno;
struct node *next;
struct node *prev;
};
typedef struct node NODE;
NODE *first;
NODE* copyNode(EMP e)
{
case 2 :
if(first==NULL)
{
printf("List is Empty\n");
}
else
{
printf(" Node Count=%d\t & Elements in the list are : \n", count());
displayList();
}
break;
case 3 :
printf(" 1. Insert at End and 2 Delete From End=");
scanf("%d",&ch);
if(ch==1)
{
e=input();
addrear(e);
}
else if(ch==2)
deleterear();
else
printf(" Sorry wrong operation\n");
break;
case 4 :
printf(" 1. Insert at Front and 2 Delete From Front=");
scanf("%d",&ch);
if(ch==1)
Output:
List Operations
===============
1.Create a DLL of N Employees Data by using end insertion
2.Display the status of DLL and count the number of nodes in it
3.Perform Insertion and Deletion at End of DLL
4.Perform Insertion and Deletion at Front of DLL
5.Demonstration of this DLL as Double Ended Queue
6.Exit
Enter your choice : 1
Enter the number of Employees 2
Enter the details of Employee 1
Enter SSN: 111
Enter Name: Ram
List Operations
===============
1.Create a DLL of N Employees Data by using end insertion
2.Display the status of DLL and count the number of nodes in it
3.Perform Insertion and Deletion at End of DLL
4.Perform Insertion and Deletion at Front of DLL
5.Demonstration of this DLL as Double Ended Queue
6.Exit
Enter your choice : 2
Node Count=2 & Elements in the list are :
SSN Name Dept Designation salary Phone
111 Ram Sales Manager 50000 9141000000
222 Sham Design Manager 60000 9876543210
List Operations
===============
1.Create a DLL of N Employees Data by using end insertion
2.Display the status of DLL and count the number of nodes in it
3.Perform Insertion and Deletion at End of DLL
4.Perform Insertion and Deletion at Front of DLL
5.Demonstration of this DLL as Double Ended Queue
6.Exit
List Operations
===============
1.Create a DLL of N Employees Data by using end insertion
2.Display the status of DLL and count the number of nodes in it
3.Perform Insertion and Deletion at End of DLL
4.Perform Insertion and Deletion at Front of DLL
5.Demonstration of this DLL as Double Ended Queue
6.Exit
Enter your choice : 2
Node Count=3 & Elements in the list are :
SSN Name Dept Designation salary Phone
111 Ram Sales Manager 50000 9141000000
222 Sham Design Manager 60000 9876543210
333 Ravi Finance Manager 65000 9876500000
List Operations
===============
1.Create a DLL of N Employees Data by using end insertion
2.Display the status of DLL and count the number of nodes in it
3.Perform Insertion and Deletion at End of DLL
4.Perform Insertion and Deletion at Front of DLL
5.Demonstration of this DLL as Double Ended Queue
6.Exit
Enter your choice : 4
1. Insert at Front and 2 Delete From Front=2
SSN Name Dept Designation Salary Phone
111 Ram Sales Manager 50000 9141000000
List Operations
===============
1.Create a DLL of N Employees Data by using end insertion
2.Display the status of DLL and count the number of nodes in it
3.Perform Insertion and Deletion at End of DLL
4.Perform Insertion and Deletion at Front of DLL
5.Demonstration of this DLL as Double Ended Queue
6.Exit
Enter your choice : 5
This DLL can be used as Double Ended Queue by inserting and deleting from both ends
List Operations
===============
1.Create a DLL of N Employees Data by using end insertion
2.Display the status of DLL and count the number of nodes in it
3.Perform Insertion and Deletion at End of DLL
4.Perform Insertion and Deletion at Front of DLL
5.Demonstration of this DLL as Double Ended Queue
6.Exit
Enter your choice : 6
Develop a Program in C for the following operations on Singly Circular Linked List
(SCLL) with header nodes
a. Represent and Evaluate a Polynomial P(x,y,z) = 6x2y2z-4yz5+3x3yz+2xy5z-2xyz3
b. Find the sum of two polynomials POLY1(x,y,z) and POLY2(x,y,z) and store the
result in POLYSUM(x,y,z).
Support the program with appropriate functions for each of the above operations.
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
struct node
{
int coef,px, py,pz; struct node *next;
};
typedef struct node NODE; NODE *first;
void display()
{
NODE *cur;
if(first==NULL)
{
printf("List is empty\n");
return;
}
cur=first;
while(cur->next!=first)
{
printf("%d ",cur->coef);
printf(" x^%d",cur->px);
printf(" y^%d",cur->py);
printf(" z^%d + ",cur->pz);
cur=cur->next;
}
printf("%d ",cur->coef);
printf(" x^%d",cur->px);
printf(" y^%d",cur->py);
printf(" z^%d\n",cur->pz);
return;
int main()
{
int coef,px,py,pz, x,y,z,i;
int val;
first=NULL;
while(1)
{
printf("1. Insert polynomial at end\n");
printf("2. Display\n");
printf("3. Evaluate\n");
printf("4. Exit\n");
printf("Enter Choice= \t");
scanf("%d",&i);
switch(i)
{
case 1 : printf("Enter Coefficient= \t");
Output:
1. Insert polynomial at end
2. Display
3. Evaluate
4. Exit
Enter Choice= 1
Enter Coefficient= 4
Enter powers of x y z values= 3 3 2
1. Insert polynomial at end
2. Display
3. Evaluate
4. Exit
Enter Choice= 1
Enter Coefficient= 5
Enter powers of x y z values= 3 2 2
1. Insert polynomial at end
2. Display
Value=1548
1. Insert polynomial at end
2. Display
3. Evaluate
4. Exit
Enter Choice= 4
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
cur2=h2->link;
while(cur2 != h2) //remaining poly2 nodes inserted to poly3
{
void main()
{
int choice,data,item,pos; NODE head1,head2,head3;
head1=(NODE)malloc(sizeof(struct node));
head1->link=head1; //poly1
head2=(NODE)malloc(sizeof(struct node));
head2->link=head2; //poly2
printf("\nPolynomial 2 is :");
display(head2);
Output:
1.Create Polynomial 1
2.Create Polynomial 2
Develop a menu driven Program in C for the following operations on Binary Search Tree (BST) of
Integers .
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
int choice,data,key;
struct node
{
int info;
struct node *lchild,*rchild;
};
typedef struct node *NODE;
int main()
{
NODE root=NULL;
NODE CREATE(NODE,int);
void INORDER(NODE),POSTORDER(NODE),PREORDER(NODE);
NODE SEARCH_NODE(NODE,int);
while(1)
{
printf("\n1:CREATE\n2:TREE TRAVERSAL\n3.SEARCH\n4.EXIT");
printf("\nEnter your choice\n");
scanf("%d",&choice);
switch(choice)
{
case 1: printf("\nEnter data to be inserted\n");
scanf("%d",&data);
root=CREATE(root,data);
break;
1:CREATE
2:TREE TRAVERSAL
3.SEARCH
4.EXIT
Enter your choice
2
EMPTY TREE
1:CREATE
2:TREE TRAVERSAL
3.SEARCH
4.EXIT
Enter your choice
1
1:CREATE
2:TREE TRAVERSAL
3.SEARCH
4.EXIT
Enter your choice
1
1:CREATE
2:TREE TRAVERSAL
3.SEARCH
1:CREATE
2:TREE TRAVERSAL
3.SEARCH
4.EXIT
Enter your choice
1
1:CREATE
2:TREE TRAVERSAL
3.SEARCH
4.EXIT
Enter your choice
1
1:CREATE
2:TREE TRAVERSAL
3.SEARCH
4.EXIT
Enter your choice
1
1:CREATE
2:TREE TRAVERSAL
3.SEARCH
4.EXIT
Enter your choice
1
1:CREATE
2:TREE TRAVERSAL
3.SEARCH
4.EXIT
Enter your choice
1
1:CREATE
2:TREE TRAVERSAL
3.SEARCH
4.EXIT
Enter your choice
1:CREATE
2:TREE TRAVERSAL
3.SEARCH
4.EXIT
Enter your choice
1
1:CREATE
2:TREE TRAVERSAL
3.SEARCH
4.EXIT
Enter your choice
2
Data 14 is found
1:CREATE
2:TREE TRAVERSAL
3.SEARCH
4.EXIT
Enter your choice
3
Design, develop and implement a Program in C for the following operations on Graph (G) of Cities
Create a Graph of N cities using Adjacency Matrix. Print all the nodes reachable from a given
starting node in a digraph using BFS method
#include<stdio.h>
#include<stdlib.h>
int n,a[10][10],i,j,source,s[10],choice,count;
void bfs(int n,int a[10][10],int source,int s[]) //BFS Algorithm
{
int q[10],u;
int front=1,rear=1;
s[source]=1;
q[rear]=source;
while(front<=rear)
{
u=q[front];
front=front+1;
for(i=1;i<=n;i++)
if(a[u][i]==1 && s[i]==0)
{
rear=rear+1;
q[rear]=i;
s[i]=1;
}
}
}
int main()
{
printf("Enter the number of nodes : ");
scanf("%d",&n);
printf("\n Enter the adjacency matrix\n");
for(i=1;i<=n;i++) //Provide matrix of 0’s and 1’s
scanf("%d",&a[i][j]);
while(1)
{
printf("\nEnter your choice\n");
printf("1.BFS\n 2.Exit\n");
scanf("%d",&choice);
switch(choice)
{
case 1: printf("\n Enter the source :");
scanf("%d",&source); //Provide source for BFS
for(i=1;i<=n;i++)
s[i]=0;
bfs(n,a,source,s);
for(i=1;i<=n;i++)
{
if(s[i]==0)
printf("\n The node %d is not reachable",i);
else
printf("\n The node %d is reachable",i);
}
break;
case 2:
exit(0);
}
}
}
01010
00100
10000
00100
00110
1.BFS
2.Exit
2.Exit
1.BFS
2.Exit
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.
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.
#include <stdio.h>
#include <stdlib.h>
#define MAX 5
#define mod(x) x%MAX
void linear_prob(int a[],int num,int key)
{
if(a[key]==-1)
a[key]=num;
else
{
printf("\nCollision detected!!");
int i;
for(i=mod(key+1);i!=key;i=mod(++i))
if(a[i]==-1)
break;
if(i!=key)
{
printf("\nCollision avoided successfully\n");
a[i]=num;
}
else
printf("\nHash table is full\n");
}
}
void display(int a[])
Output:
Program 1
Write a C program to implement pointer operations.
// Program to implement pointer operations
#include<stdio.h>
#include<conio.h>
void main()
Program2
Write a C program to exchange two values using pointers.
// Program to exchange two values
Program 3
#include <stdio.h>
#include <conio.h>
struct book
{ int
i_book_id
; char
*c_name;
float
f_price;
} b;
void main()
clrscr();
b.i_book_id=1;
b.c_name = "Fundamentals of Data Structure";
b.f_price = 390.5;
printf("Book Id is : %d \n", b.i_book_id);
printf("Name is : %s \n", b.c_name);
printf("Price is : %f \n", b.f_price);
getch();
}
APPENDIX B:
A data structure is a way of organizing data that considers not only the items stored,
but also their relationship to each other.
2. List out the areas in which data structures are applied extensively?
· Compiler Design
· Operating System
· Numerical Analysis
· Graphics
· Artificial Intelligence
· Simulation
3. What are the major data structures used in the following areas: RDBMS,
Network data model and Hierarchical data model?
Stack. Because of its LIFO (Last In First Out) property it remembers its 'caller' so
knows whom to return when the function has to return.
Singly linked list is a collection of nodes. Each node has element and address of the
next element. With that address only forward traversal is possible i.e. single link
By repointing the previous and the next elements of existing nodes to the new node.
· Index generation.
Linked List
· Brackets or Parenthesis,
· Exponentiation,
· Multiplication or division,
· Addition or subtraction.
16. Give the advantages of using post fix notations over infix notations?
18. In RDBMS, what is the efficient data structure used in the internal storage
representation?
B+ tree. Because in B+ tree, all the data is stored only in leaf nodes, that makes
searching easier. This corresponds to the records that shall be stored in leaf nodes.