DSA Lab
DSA Lab
b. Write func ons create(), read() and display(); to create the calendar, to read the data from the
keyboard and to print weeks ac vity details report on screen.
#include <stdio.h>
#include <stdlib.h>
struct Day {
char *dayName;
int date;
};
scanf("%s", day->dayName);
scanf("%d", &day->date);
create(&calendar[i]);
prin ("\n");
free(calendar[i].dayName);
free(calendar[i].ac vity);
int main() {
int size;
scanf("%d", &size);
if (calendar == NULL) {
prin ("Memory alloca on failed. Exi ng program.\n");
return 1;
read(calendar, size);
display(calendar, size);
freeMemory(calendar, size);
free(calendar);
return 0;
OUTPUT:
Day 1:
Date: 1
Ac vity: Learning
Day 2:
Date: 2
Ac vity: Coding
Day 3:
Day Name: Tuesday
Date: 3
Ac vity: Tes ng
Day 4:
Date: 4
Ac vity: Debugging
Day 5:
Date: 5
Ac vity: Publishing
Day 6:
Date: 6
Ac vity: Marke ng
Day 7:
Date: 7
Ac vity: Earning
b. Perform Pa ern Matching Opera on: 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.
#include<stdio.h>
int c = 0, m = 0, i = 0, j = 0, k, flag = 0;
void stringmatch()
if (str[m] == pat[i])
i++;
m++;
if (pat[i] == '\0')
flag = 1;
res[j] = rep[k];
i = 0;
c = m;
else
res[j] = str[c];
j++;
c++;
m = c;
i = 0;
res[j] = '\0';
void main()
{
gets(str);
gets(pat);
gets(rep);
stringmatch();
if (flag == 1)
prin ("\nThe string a er pa ern match and replace is: \n %s ", res);
else
OUTPUT:
**************************OUTPUT 1*******************************
Designed by vtucode
Designed by Braham
**************************OUTPUT 2*******************************
Designed by Developer
3. Develop a menu driven Program in C for the following opera ons on STACK of Integers (Array
Implementa on of Stack with maximum size MAX)
a. Push an Element on to Stack
b. Pop an Element from Stack
c. Demonstrate how Stack can be used to check Palindrome
d. Demonstrate Overflow and Underflow situa ons on Stack
e. Display the status of Stack
f. Exit
#include<stdio.h>
#include<stdlib.h>
#define MAX 3
int s[MAX];
int pop();
void palindrome();
void display();
void main()
while (1)
prin ("\n=>5.Exit");
switch (choice)
case 1:
push(item);
break;
case 2:
item = pop();
if (item != -1)
break;
case 3:
palindrome();
break;
case 4:
display();
break;
case 5:
exit(1);
default:
break;
if (top == MAX - 1)
return;
top = top + 1;
s[top] = item;
int pop()
int item;
if (top == -1)
return -1;
}
item = s[top];
top = top - 1;
return item;
void display()
int i;
if (top == -1)
return;
void palindrome()
int flag = 1, i;
{
if (s[i] != s[top - i])
flag = 0;
break;
if (flag == 1)
else
OUTPUT:
-----------Menu----------- :
=>3.Palindrome demo
=>4.Display
=>5.Exit
-----------Menu----------- :
=>3.Palindrome demo
=>4.Display
=>5.Exit
-----------Menu----------- :
=>3.Palindrome demo
=>4.Display
=>5.Exit
-----------Menu----------- :
=>3.Palindrome demo
=>4.Display
=>5.Exit
-----------Stack overflow-----------
-----------Menu----------- :
=>4.Display
=>5.Exit
| 13 |
| 12 |
| 11 |
-----------Menu----------- :
=>3.Palindrome demo
=>4.Display
=>5.Exit
-----------Menu----------- :
=>3.Palindrome demo
=>4.Display
=>5.Exit
| 12 |
| 11 |
-----------Menu----------- :
=>3.Palindrome demo
=>4.Display
=>5.Exit
-----------Menu----------- :
=>3.Palindrome demo
=>4.Display
=>5.Exit
=>3.Palindrome demo
=>4.Display
=>5.Exit
-----------Stack underflow-----------
-----------Menu----------- :
=>3.Palindrome demo
=>4.Display
=>5.Exit
-----------Stack is empty-----------
-----------Menu----------- :
=>3.Palindrome demo
=>4.Display
=>5.Exit
Enter your choice: 1
-----------Menu----------- :
=>3.Palindrome demo
=>4.Display
=>5.Exit
-----------Menu----------- :
=>3.Palindrome demo
=>4.Display
=>5.Exit
-----------Menu----------- :
=>3.Palindrome demo
=>4.Display
=>5.Exit
| 11 |
| 22 |
| 11 |
| 11 |
| 22 |
| 11 |
It is palindrome number
-----------Menu----------- :
=>3.Palindrome demo
=>4.Display
=>5.Exit
-----------Menu----------- :
=>3.Palindrome demo
=>4.Display
=>5.Exit
-----------Menu----------- :
=>3.Palindrome demo
=>4.Display
=>5.Exit
-----------Menu----------- :
=>3.Palindrome demo
=>4.Display
=>5.Exit
-----------Menu----------- :
=>3.Palindrome demo
=>4.Display
=>5.Exit
| 22 |
| 33 |
| 11 |
| 11 |
| 33 |
| 22 |
-----------Menu----------- :
=>3.Palindrome demo
=>4.Display
=>5.Exit
4. Develop a Program in C for conver ng an Infix Expression to Pos ix Expression. Program should
support for both parenthesized and free parenthesized expressions with the operators: +, -, *, /,
(Remainder), ^ (Power) and alphanumeric operands.
#include<stdio.h>
#include<stdlib.h>
void evaluate();
void push(char);
char pop();
int prec(char);
void main()
scanf("%s", infix);
evaluate();
void evaluate()
int i = 0, j = 0;
push('#');
symb = infix[i];
switch (symb)
case '(':
push(symb);
break;
case ')':
temp = pop();
j++;
temp = pop();
break;
case '+':
case '-':
case '*':
case '/':
case '%':
case '^':
case '$':
temp = pop();
j++;
push(symb);
break;
default:
j++;
}
while (top > 0)
temp = pop();
j++;
top = top + 1;
stack[top] = item;
char pop()
char item;
item = stack[top];
top = top - 1;
return item;
int p;
switch (symb)
case '#':
p = -1;
break;
case '(':
case ')':
p = 0;
break;
case '+':
case '-':
p = 1;
break;
case '*':
case '/':
case '%':
p = 2;
break;
case '^':
case '$':
p = 3;
break;
return p;
OUTPUT:
(a+b)*c/d^5%1
ab+c*d5^/1%
5. Develop a Program in C for the following Stack Applica ons.
a. Evalua on of Suffix expression with single digit operands and operators: +, -, *, /, %,^.
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
top = top + 1;
s[top] = item;
int pop()
int item;
item = s[top];
top = top - 1;
return item;
void main()
if (isdigit(symb))
push(symb - '0');
else
op2 = pop();
op1 = pop();
switch (symb)
case '+':
push(op1 + op2);
break;
case '-':
push(op1 - op2);
break;
case '*':
push(op1 * op2);
break;
case '/':
push(op1 / op2);
break;
case '%':
push(op1 % op2);
break;
case '$':
case '^':
push(pow(op1, op2));
break;
default:
push(0);
res = pop();
OUTPUT:
623+-382/+*2$3+
Result = 52
#include <stdio.h>
if (n == 0)
return;
void main()
int n;
}
OUTPUT:
6. Develop a menu driven Program in C for the following opera ons on Circular QUEUE of
Characters (Array Implementa on 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 situa ons on Circular QUEUE
d. Display the status of Circular QUEUE
e. Exit
#include<stdio.h>
#include<stdlib.h>
#define MAX 5
char circular_queue[MAX];
int isEmpty()
return 1;
else
return 0;
}
int isFull()
return 1;
else
return 0;
if (isFull())
return;
else if (isEmpty())
front = rear = 0;
else
circular_queue[rear] = element;
void deleteElement()
if (isEmpty())
{
return;
else
void display()
int i;
if (isEmpty())
return;
i = front;
do
i = (i + 1) % MAX;
prin ("\n");
}
int main()
int choice;
char element;
do
scanf("%d", &choice);
switch(choice)
case 1:
insertElement(element);
break;
case 2:
deleteElement();
break;
case 3:
display();
break;
case 4:
default:
while(choice != 4);
return 0;
OUTPUT:
1. Insert an Element
2. Delete an Element
4. Exit
1. Insert an Element
2. Delete an Element
4. Exit
1. Insert an Element
2. Delete an Element
3. Display Circular Queue
4. Exit
1. Insert an Element
2. Delete an Element
4. Exit
1. Insert an Element
2. Delete an Element
4. Exit
1. Insert an Element
2. Delete an Element
4. Exit
1. Insert an Element
2. Delete an Element
4. Exit
Exi ng...
7. Develop a menu driven Program in C for the following opera ons 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 inser on.
b. Display the status of SLL and count the number of nodes in it
c. Perform Inser on / Dele on at End of SLL
d. Perform Inser on / Dele on at Front of SLL(Demonstra on of stack)
e. Exit
#include<stdio.h>
#include<stdlib.h>
struct node
int sem;
};
int count = 0;
NODE create()
{
NODE snode;
if (snode == NULL)
exit(1);
scanf("%s %s %s %d %ld", snode -> usn, snode -> name, snode -> branch, & snode -> sem, & snode
-> phone);
count++;
return snode;
NODE temp;
temp = create();
if (start == NULL)
return temp;
return temp;
NODE deletefront()
{
NODE temp;
if (start == NULL)
return NULL;
prin ("\nThe Student node with usn:%s is deleted ", start -> usn);
count--;
free(start);
return NULL;
temp = start;
prin ("\nThe Student node with usn:%s is deleted", temp -> usn);
count--;
free(temp);
return start;
NODE insertend()
temp = create();
if (start == NULL)
return temp;
}
cur = start;
return start;
NODE deleteend()
if (start == NULL)
return NULL;
prin ("\nThe student node with the usn:%s is deleted", start -> usn);
free(start);
count--;
return NULL;
prev = NULL;
cur = start;
prev = cur;
cur = cur -> link;
prin ("\nThe student node with the usn:%s is deleted", cur -> usn);
free(cur);
count--;
return start;
void display()
NODE cur;
int num = 1;
if (start == NULL)
return;
cur = start;
prin ("\n|%d| |USN:%s| |Name:%s| |Branch:%s| |Sem:%d| |Ph:%ld|", num, cur -> usn, cur ->
name, cur -> branch, cur -> sem, cur -> phone);
num++;
void stackdemo()
int ch;
while (1)
prin ("\n1:Push opera on \n2: Pop opera on \n3: Display \n4:Exit \n");
switch (ch)
case 1:
break;
case 2:
start = deletefront();
break;
case 3:
display();
break;
default:
return;
return;
int main()
{
int ch, i, n;
while (1)
prin ("\n--------Menu--------");
prin ("\n2:DisplayStatus");
prin ("\n3:InsertAtEnd");
prin ("\n4:DeleteAtEnd");
switch (ch)
case 1:
break;
case 2:
display();
break;
case 3:
start = insertend();
break;
case 4:
start = deleteend();
break;
case 5:
stackdemo();
break;
case 6:
exit(0);
default:
OUTPUT:
--------Menu--------
2:DisplayStatus
3:InsertAtEnd
4:DeleteAtEnd
6:Exit
1ME21CS017
Braham
CSE
8768586443
1ME21CS015
Bikash
CSE
8734687996
1ME21AI015
Shoaib
AI&ML
6748353877
--------Menu--------
2:DisplayStatus
3:InsertAtEnd
4:DeleteAtEnd
6:Exit
Enter your choice:2
No of student nodes is 3
--------Menu--------
2:DisplayStatus
3:InsertAtEnd
4:DeleteAtEnd
6:Exit
1ME21CS068
Rajan
CSE
3426527765
--------Menu--------
2:DisplayStatus
3:InsertAtEnd
4:DeleteAtEnd
6:Exit
No of student nodes is 4
--------Menu--------
2:DisplayStatus
3:InsertAtEnd
4:DeleteAtEnd
6:Exit
--------Menu--------
2:DisplayStatus
3:InsertAtEnd
4:DeleteAtEnd
6:Exit
No of student nodes is 3
--------Menu--------
2:DisplayStatus
3:InsertAtEnd
4:DeleteAtEnd
6:Exit
--------Menu--------
2:DisplayStatus
3:InsertAtEnd
4:DeleteAtEnd
6:Exit
1:Push opera on
2: Pop opera on
3: Display
4:Exit
1ME21CS005
Aman
CSE
6587594335
1:Push opera on
2: Pop opera on
3: Display
4:Exit
Enter your choice for stack demo:3
No of student nodes is 3
1: Push opera on
2: Pop opera on
3: Display
4: Exit
1ME21CS092
Shubham
CSE
9869754354
1:Push opera on
2: Pop opera on
3: Display
4:Exit
Enter your choice for stack demo:3
No of student nodes is 4
1:Push opera on
2: Pop opera on
3: Display
4:Exit
1:Push opera on
2: Pop opera on
3: Display
4:Exit
No of student nodes is 3
1: Push opera on
2: Pop opera on
3: Display
4: Exit
--------Menu--------
2:DisplayStatus
3:InsertAtEnd
4:DeleteAtEnd
6:Exit
8. Develop a menu driven Program in C for the following opera ons on Doubly Linked List (DLL) of
Employee Data with the fields: SSN, Name, Dept, Designa on, Sal, PhNo.
a. Create a DLL of N Employees Data by using end inser on.
b. Display the status of DLL and count the number of nodes in it
c. Perform Inser on and Dele on at End of DLL
d. Perform Inser on and Dele on at Front of DLL
e. Demonstrate how this DLL can be used as Double Ended Queue.
f. Exit
#include<stdio.h>
#include<stdlib.h>
struct node
int sal;
};
int count = 0;
NODE create()
NODE enode;
if (enode == NULL)
exit(0);
scanf("%s %s %s %s %d %ld", enode -> ssn, enode -> name, enode -> dept, enode -> designa on, &
enode -> sal, & enode -> phone);
count++;
return enode;
}
NODE temp;
temp = create();
if (first == NULL)
return temp;
return temp;
void display()
NODE cur;
int nodeno = 1;
cur = first;
if (cur == NULL)
nodeno++;
}
NODE deletefront()
NODE temp;
if (first == NULL)
return NULL;
prin ("\nThe employee node with the ssn:%s is deleted ", first -> ssn);
free(first);
count--;
return NULL;
temp = first;
prin ("\nThe employee node with the ssn:%s is deleted ", temp -> ssn);
free(temp);
count--;
return first;
NODE insertend()
temp = create();
if (first == NULL)
return temp;
cur = first;
return first;
NODE deleteend()
if (first == NULL)
return NULL;
prin ("\nThe employee node with the ssn:%s is deleted ", first -> ssn);
free(first);
count--;
return NULL;
}
prev = NULL;
cur = first;
prev = cur;
prin ("\nThe employee node with the ssn:%s is deleted ", cur -> ssn);
free(cur);
count--;
return first;
void deqdemo()
int ch;
while (1)
switch (ch)
case 1:
first = inser ront();
break;
case 2:
first = deletefront();
break;
case 3:
first = insertend();
break;
case 4:
first = deleteend();
break;
case 5:
display();
break;
default:
return;
void main()
int ch, i, n;
while (1)
prin ("\n\n--------Menu--------");
prin ("\n2:DisplayStatus");
prin ("\n3:InsertAtEnd");
prin ("\n4:DeleteAtEnd");
prin ("\n5:InsertAtFront");
prin ("\n6:DeleteAtFront");
switch (ch)
case 1:
first = insertend();
break;
case 2:
display();
break;
case 3:
first = insertend();
break;
case 4:
first = deleteend();
break;
case 5:
break;
case 6:
first = deletefront();
break;
case 7:
deqdemo();
break;
case 8:
exit(0);
default:
OUTPUT:
--------Menu--------
2:DisplayStatus
3:InsertAtEnd
4:DeleteAtEnd
5:InsertAtFront
6:DeleteAtFront
8:Exit
1EPL
Braham
Developer
Senior
13627
8476283712
2EPL
Aman
Trader
Manager
20000
2763578156
--------Menu--------
2:DisplayStatus
3:InsertAtEnd
4:DeleteAtEnd
5:InsertAtFront
6:DeleteAtFront
8:Exit
No of employee nodes is 2
--------Menu--------
3:InsertAtEnd
4:DeleteAtEnd
5:InsertAtFront
6:DeleteAtFront
8:Exit
3EPL
Bikash
Mee ng
Manager
30000
8237462936
--------Menu--------
2:DisplayStatus
3:InsertAtEnd
4:DeleteAtEnd
5:InsertAtFront
6:DeleteAtFront
8:Exit
No of employee nodes is 3
--------Menu--------
2:DisplayStatus
3:InsertAtEnd
4:DeleteAtEnd
5:InsertAtFront
6:DeleteAtFront
8:Exit
4EPL
Shoaib
Digital Marke ng
Manager
40000
2835826437
--------Menu--------
2:DisplayStatus
3:InsertAtEnd
4:DeleteAtEnd
5:InsertAtFront
6:DeleteAtFront
No of employee nodes is 4
--------Menu--------
2:DisplayStatus
3:InsertAtEnd
4:DeleteAtEnd
5:InsertAtFront
6:DeleteAtFront
8:Exit
--------Menu--------
2:DisplayStatus
3:InsertAtEnd
4:DeleteAtEnd
5:InsertAtFront
6:DeleteAtFront
8:Exit
--------Menu--------
2:DisplayStatus
3:InsertAtEnd
4:DeleteAtEnd
5:InsertAtFront
6:DeleteAtFront
8:Exit
No of employee nodes is 2
--------Menu--------
2:DisplayStatus
3:InsertAtEnd
4:DeleteAtEnd
5:InsertAtFront
6:DeleteAtFront
7:Double Ended Queue Demo using DLL
8:Exit
1:InsertQueueFront
2: DeleteQueueFront
3:InsertQueueRear
4:DeleteQueueRear
5:DisplayStatus
6: Exit
1:InsertQueueFront
2: DeleteQueueFront
3:InsertQueueRear
4:DeleteQueueRear
5:DisplayStatus
6: Exit
1:InsertQueueFront
2: DeleteQueueFront
3:InsertQueueRear
4:DeleteQueueRear
5:DisplayStatus
6: Exit
1:InsertQueueFront
2: DeleteQueueFront
3:InsertQueueRear
4:DeleteQueueRear
5:DisplayStatus
6: Exit
--------Menu--------
2:DisplayStatus
3:InsertAtEnd
4:DeleteAtEnd
5:InsertAtFront
6:DeleteAtFront
8:Exit
9. Develop a Program in C for the following opera ons 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).
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
struct node
int coef;
};
NODE getnode()
NODE x;
if (x == NULL)
return NULL;
return x;
NODE a ach(int coef, int xexp, int yexp, int zexp, NODE head)
temp = getnode();
temp -> coef = coef;
return head;
return head;
}
NODE temp;
return;
prin ("%dx^%dy^%dz^%d", temp -> coef, temp -> xexp, temp -> yexp, temp -> zexp);
if (temp != head)
int x, y, z, sum = 0;
NODE poly;
sum += poly -> coef * pow(x, poly -> xexp) * pow(y, poly -> yexp) * pow(z, poly -> zexp);
return sum;
NODE a, b;
int coef;
while (1)
if (a -> xexp == b -> xexp && a -> yexp == b -> yexp && a -> zexp == b -> zexp)
a = a -> link;
b = b -> link;
break;
case -1:
head3 = a ach(b -> coef, b -> xexp, b -> yexp, b -> zexp, head3);
b = b -> link;
break;
case 0:
head3 = a ach(a -> coef, a -> xexp, a -> yexp, a -> zexp, head3);
a = a -> link;
break;
head3 = a ach(b -> coef, b -> xexp, b -> yexp, b -> zexp, head3);
b = b -> link;
break;
head3 = a ach(a -> coef, a -> xexp, a -> yexp, a -> zexp, head3);
a = a -> link;
break;
head3 = a ach(b -> coef, b -> xexp, b -> yexp, b -> zexp, head3);
b = b -> link;
break;
case 1:
head3 = a ach(a -> coef, a -> xexp, a -> yexp, a -> zexp, head3);
a = a -> link;
break;
break;
case -1:
head3 = a ach(b -> coef, b -> xexp, b -> yexp, b -> zexp, head3);
b = b -> link;
break;
case 0:
head3 = a ach(a -> coef, a -> xexp, a -> yexp, a -> zexp, head3);
a = a -> link;
break;
head3 = a ach(b -> coef, b -> xexp, b -> yexp, b -> zexp, head3);
b = b -> link;
break;
case 1:
head3 = a ach(a -> coef, a -> xexp, a -> yexp, a -> zexp, head3);
a = a -> link;
break;
}
break;
case -1:
head3 = a ach(b -> coef, b -> xexp, b -> yexp, b -> zexp, head3);
b = b -> link;
break;
case 1:
head3 = a ach(a -> coef, a -> xexp, a -> yexp, a -> zexp, head3);
a = a -> link;
break;
break;
while (a != head1)
head3 = a ach(a -> coef, a -> xexp, a -> yexp, a -> zexp, head3);
a = a -> link;
while (b != head2)
head3 = a ach(b -> coef, b -> xexp, b -> yexp, b -> zexp, head3);
b = b -> link;
return head3;
}
void main()
head = getnode();
head1 = getnode();
head2 = getnode();
head3 = getnode();
while (1)
prin ("\n--------Menu--------");
switch (ch)
case 1:
head = read_poly(head);
display(head);
res = poly_evaluate(head);
case 2:
head1 = read_poly(head1);
display(head1);
head2 = read_poly(head2);
display(head2);
display(head3);
break;
case 3:
exit(0);
OUTPUT:
--------Menu--------
Coef = -4
Coef = 3
Coef = 2
Coef = -2
--------Menu--------
Coef = 6
Coef = 3
Coef = 5
Coef = 10
Coef = 5
Polynomial 1 is:
Coef = 8
Coef = 4
Coef = 30
Coef = 20
Coef = 3
Polynomial 2 is:
--------Menu--------
b. Write func ons create(), read() and display(); to create the calendar, to read the data from the
keyboard and to print weeks ac vity details report on screen.
#include<stdio.h>
#include<stdlib.h>
struct BST
int data;
};
NODE temp;
return temp;
else
{
if (root -> rchild == NULL)
else
int key;
NODE cur;
if (root == NULL)
return;
cur = root;
return;
else
}
prin ("\nKey element is not found in the BST ");
if (root != NULL)
if (root != NULL)
if (root != NULL)
}
}
void main()
while (1)
prin ("\n4.Exit");
switch (ch)
case 1:
newnode = create();
if (root == NULL)
root = newnode;
else
insert(root, newnode);
break;
case 2:
if (root == NULL)
prin ("\nTree Is Not Created ");
else
preorder(root);
inorder(root);
postorder(root);
break;
case 3:
search(root);
break;
case 4:
exit(0);
Output:
-------BST MENU-------
1.Create a BST
2.Search
3.BST Traversals:
4.Exit
-------BST MENU-------
1.Create a BST
2.Search
3.BST Traversals:
4.Exit
-------BST MENU-------
1.Create a BST
2.Search
3.BST Traversals:
4.Exit
-------BST MENU-------
1.Create a BST
2.Search
3.BST Traversals:
4.Exit
-------BST MENU-------
1.Create a BST
2.Search
3.BST Traversals:
4.Exit
11. Develop a Program in C for the following opera ons on Graph(G) of Ci es.
a. Create a Graph of N ci es using Adjacency Matrix.
b. Print all the nodes reachable from a given star ng node in a digraph using DFS/BFS method.
#include<stdio.h>
#include<stdlib.h>
void bfs(int v)
int i, cur;
visited[v] = 1;
q[++rear] = v;
cur = q[++front];
q[++rear] = i;
visited[i] = 1;
void dfs(int v)
int i;
visited[v] = 1;
s[++top] = v;
dfs(i);
}
int main()
visited[i] = 0;
prin ("\n==>1. BFS: Print all nodes reachable from a given star ng node");
prin ("\n==>2. DFS: Print all nodes reachable from a given star ng node");
prin ("\n==>3:Exit");
switch (ch)
case 1:
bfs(start);
{
if (visited[i] == 0)
break;
case 2:
dfs(start);
break;
case 3:
exit(0);
default:
OUTPUT:
*************************case-1*************************
0101
0010
0001
0000
==>1. BFS: Print all nodes reachable from a given star ng node
==>2. DFS: Print all nodes reachable from a given star ng node
==>3:Exit
0101
0010
0001
0000
==>1. BFS: Print all nodes reachable from a given star ng node
==>2. DFS: Print all nodes reachable from a given star ng node
==>3:Exit
*************************case-3*************************
0101
0010
0001
0000
==>1. BFS: Print all nodes reachable from a given star ng node
==>2. DFS: Print all nodes reachable from a given star ng node
==>3:Exit
*************************case-4*************************
0101
0010
0001
0000
==>1. BFS: Print all nodes reachable from a given star ng node
==>2. DFS: Print all nodes reachable from a given star ng node
==>3:Exit
12. 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
loca ons with L as the set of memory addresses (2-digit) of loca ons in HT. Let the keys in K and
addresses in L are Integers. Develop a Program in C that uses Hash func on 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>
int key[20], n, m;
int count = 0;
void insert(int key)
index = key % m;
index = (index + 1) % m;
ht[index] = key;
count++;
void display()
int i;
if (count == 0)
return;
void main()
int i;
ht[i] = -1;
prin ("\nEnter the four digit key values (K) for N Employee Records:\n ");
if (count == m)
prin ("\n-----Hash table is full. Cannot insert the record %d key-----", i + 1);
break;
insert(key[i]);
display();
OUTPUT:
Enter the two digit memory loca ons (m) for hash table:15
Enter the four digit key values (K) for N Employee Records:
4020
4560
9908
6785
0423
7890
6547
3342
9043
6754
T[6] --> -1
T[9] --> -1
T[10] --> -1
T[11] --> -1
T[14] --> -1