DSA LAB Manual (2023-24)
DSA LAB Manual (2023-24)
DATA STRUCTURES
LABORATORY
Course Code: BCSL305
(Academic Year: 2023-24)
Department of CSE/ISE/AIML
BMS Institute of Technology and Management
Bengaluru-98
B.E. COMPUTER SCIENCE AND ENGINEERING
Choice Based Credit System (CBCS)
SEMESTER - III
DATA STRUCTURES LABORATORY (2:0:0) 1
(Effective from the academic year 2022-23)
Course Code BCSL305 CIE Marks 50
Teaching Hours/Week (L:T:P) 0:0:2 SEE Marks 50
Total Number of Contact Hours 26 Exam Hours 02
Course Objectives:
This course enables students to:
1. Develop linear data structures and their applications such as stacks, queues and lists.
2. Develop non-linear data structures and their applications such as trees and graphs
sorting and searching algorithms.
Descriptions:
Descriptions: Design, develop, and implement the specified Data Structure as given in the
list given below using C Language under LINUX /Windows environment.
Sl. No Programs List
1 Design, Develop and Implement a menu driven Program in C for the following
operations on STACK of Integers (Array Implementation of Stack with maximum size
MAX)
a. Push an Element on to Stack
b. Pop an Element from Stack
c. Demonstrate Overflow and Underflow situations on Stack
d. Display the status of Stack
e. Exit
Support the program with appropriate functions for each of the above operations.
2 Design, Develop and Implement a Program in C for converting an Infix Expression to
Postfix Expression. Program should support for both parenthesized and free
parenthesized expressions with the operators: +, -, *, /, %( Remainder), ^ (Power) and
alphanumeric operands.
3 Design, Develop and Implement a Program in C for evaluation of Suffix expression with
single digit operands and operators: +, -, *, /, %, ^.
4 Design, Develop and Implement a menu driven Program in C for the following
operations on Circular QUEUE of integers (Array 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.
1. Ten marks for every experiment (10 X 10 = 100 marks), round it off to 30 marks.
2. Ten marks for every experiment will be evaluated for write-up, program execution,
the procedure followed while execution and viva voce after each exercise.
3. Internal practical test for 100 marks to be given and the marks scored will be scaled
down to 20 marks.
4. A Minimum of 20 mark is to be scored in CIE.
5. SEE examination for the Lab is to be conducted for 100 marks and reduced to 50
marks.
6. A Minimum of 18 marks is to be scored in SEE.
Note: Open Ended experiment will be done by the students in the Lab session. A
total mark of 40 is to be scored by the student from both CIE and SEE together out
of 100.
#include<stdio.h>
#include<stdlib.h>
#define SIZE 20
void push(int ele, int *top, int stack[]);
void pop(int *top, int stack[]);
void display(int top, int stack[]);
void main()
{
int choice, top=-1, ele, flag;
int stack[SIZE];
for(;;)
{
printf("Enter\n1. Push\n2. Pop\n3. Display\n4. Exit\n");
scanf("%d", &choice);
switch(choice)
{
case 1: if(top==(SIZE-1))
printf("Stack overflow!!!\n");
else
{
printf("Enter element to be pushed:\n");
scanf("%d", &ele);
push(ele, &top, stack);
}
break;
case 2: if(top==-1)
printf("Stack underflow!!!\n");
else
pop(&top, stack);
break;
case 3: if(top==-1)
printf("Stack underflow!!!\n");
else
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int G(char);
int F(char);
void infix_postfix(char infix[], char postfix[]);
void main()
{
char postfix[20],infix[20];
printf("Enter the infix expression: ");
scanf("%s",infix);
infix_postfix(infix,postfix);
printf("The Postfix expression is: ");
printf("%s",postfix);
}
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
void main()
{
int i, top=-1;
char postfix[20], sym;
double s[20],op1,op2,res;
printf("\nEnter postfix expression : ");
scanf("%s",postfix);
for(i=0; i<strlen(postfix); i++)
{
sym=postfix[i];
if(isdigit(sym))
s[++top]=sym-'0';
else
{
op2=s[top--];
op1=s[top--];
res=compute(op1,op2,sym);
s[++top]=res;
}
}
#include <stdio.h>
#include <stdlib.h>
#define QSIZE 5
int cq_full(int count)
{
return((count == QSIZE) ? 1 : 0);
}
int cq_empty(int count)
{
return((count == 0) ? 1 : 0);
}
void cq_insert(int q[], int* r, int* count)
{
int item;
if (cq_full(*count))
{
printf("\n Queue is full \n");
return;
}
printf("\n Enter item to be inserted:");
scanf("%d", &item);
*r = (*r + 1) % QSIZE;
q[*r] = item;
(*count)++;
return;
}
void cq_delete(int q[], int* f, int* count)
{
if (cq_empty(*count))
{
printf("\n Queue is empty \n");
return;
#include<stdio.h>
#include<stdlib.h>
#define SIZE 5
int main()
{
int Queue[SIZE],rear=-1,front=0,choice,item;
for(;;)
{
printf("\n1.Insert Front \n2.Insert Rear \n3.Delete Front \n4.Delete Rear
\n5.Display \n6.Exit");
printf("\nEnter choice:");
scanf("%d",&choice);
switch(choice)
{
case 1 : printf("Enter the element :");
scanf("%d",&item);
queue_insert_front(Queue,&rear,&front,item);
break;
case 2 : printf("Enter the element :");
scanf("%d",&item);
queue_insert_rear(Queue,&rear, item);
break;
case 3 :
queue_delete_front(Queue,&rear,&front);
break;
case 4 :
queue_delete_rear(Queue,&rear,&front);
break;
case 5: display(Queue,rear,front);
break;
}
}
return 0;
}
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct node
{
char name[20];
char usn[10];
char branch[5];
int sem;
char phno[10];
struct node* link;
};
typedef struct node* NODE;
//get node
NODE get_node()
{
NODE temp;
temp = (NODE)malloc(sizeof(struct node));
temp->link=NULL;
printf("\n Name: ");
scanf("%s", temp->name);
printf("\n USN: ");
scanf("%s", temp->usn);
printf("\n Branch: ");
scanf("%s", temp->branch);
printf("\n Sem: ");
scanf("%d", &temp->sem);
printf("\n Ph no: ");
scanf("%s", temp->phno);
return temp;
}
//insert front
NODE insert_front(NODE first)
printf("Name:%s\t", temp->name);
printf("USN:%s\t", temp->usn);
printf("Branch:%s\t", temp->branch);
printf("Sem:%d\t", temp->sem);
#include<stdio.h>
#include<stdlib.h>
struct node
{
int SSN;
char Name[20];
char Dept[20];
char Designation[20];
int Sal;
char Ph_No[11];
struct node *llink;
struct node *rlink;
};
typedef struct node *NODE;
NODE get_node();
NODE insert_front(NODE first);
NODE insert_rear(NODE first);
NODE delete_front(NODE first);
NODE delete_rear(NODE first);
void DLL_display(NODE first);
void main()
{
NODE first=NULL;
int choice;
for(;;)
{
printf("\nEnter\n1.Insert from front\n2.Insert from rear\n3.Delete from
front\n4.Delete from rear\n5.Display\n6.Exit:\n");
scanf("%d",&choice);
NODE get_node()
{
NODE temp;
temp=(NODE)malloc(sizeof(struct node));
temp->llink=temp->rlink=NULL;
printf("\nEnter the details of Employee:\n");
printf("Employee SSN:");
scanf("%d",&temp->SSN);
printf("Employee Name:");
scanf("%s",temp->Name);
printf("Employee Department:");
scanf("%s",temp->Dept);
printf("Employee Designation:");
scanf("%s",temp->Designation);
printf("Employee Salary:");
scanf("%d",&temp->Sal);
printf("Employee Phone Number:");
scanf("%s",temp->Ph_No);
return temp;
}
NODE insert_front(NODE first)
{
NODE temp;
temp=get_node();
#include <stdio.h>
#include <stdlib.h>
struct tnode
{
int info;
struct tnode* llink;
struct tnode* rlink;
};
TNODE get_node ()
{
TNODE temp;
temp = (TNODE)malloc(sizeof(struct tnode));
temp->llink=temp->rlink=NULL;
return temp;
}
void main()
{
TNODE root = NULL;
int choice, ele, key;
printf("\n1. Insert \n2. Search\n3. Display\n4. Exit\n");
for (;;)
{
printf(" \nEnter your choice : ");
scanf("%d", &choice);
switch (choice)
{
case 1: printf("Enter the element : ");
scanf("%d",&ele);
root = insert(root,ele);
break;
case 2: printf("Enter the element to be searched : ");
scanf("%d",&ele);
key = search(root,ele);
if (key==-1)
printf("Key not Found\n");
else
printf("Key Found\n");
break;
case 3: printf("Preorder : ");
preorder(root);
printf("\nInorder : ");
inorder(root);
printf("\nPostorder : ");
postorder(root);
printf("\n");
break;
case 4: exit(0);
default : printf("Invalid Input\n");
}
}
}
#include <stdio.h>
#include <stdlib.h>
int city[10][10],v[10],queue[10],r=0,f=1,n;
void dfs(int s)
{
int i;
v[s]=1;
for (i=1;i<=n;i++)
if (city[s][i] && !v[i])
{
printf("%d\t",i);
v[i]=1;
dfs(i);
}
return;
}
void bfs(int s)
{
int i;
for (i=1;i<=n;i++)
if (city[s][i] && !v[i])
{
queue[++r]=i;
printf("%d\t",i);
}
if (f<=r)
{
v[queue[f]]=1;
bfs(queue[++f]);
}
return;
}
#include <stdio.h>
#include <stdlib.h>
typedef struct employee {
int id;
char name[20];
int sal;
}EMP;
EMP emp[100];
int a[100], empID[100], count = 0;
int getemp(EMP emp[], int key, int ID) {
FILE* fp;
fp = fopen("out.txt", "a+");
emp[key].id = ID;
printf("\nEnter employee name and salary:\n");
scanf("%s%d", emp[key].name, &emp[key].sal);
fprintf(fp, "\n%d\t%s\t%d", emp[key].id, emp[key].name, emp[key].sal);
fclose(fp);
return key;
}
void display() {
int i;
printf("\nKey\tID\tName\tSalary");
for (i = 0; i < 100; i++)
if (a[i] != -1)
printf("\n%d\t%d\t%s\t%d", i, emp[i].id, emp[i].name,
emp[i].sal);
}
void probe(int key, int ID) {
int i = key, flag = 0;
if (count == 100) {
printf("Hash table is full.\n");
exit(0);
}
if (a[key] == -1) {
1. Design, Develop and Implement a multi stack Program in C. Design this program with menu
options and let the multi-stack house minimum of three stacks in it. Incorporate the following
functions in the program.
a. Push an Element on to a specific Stack
b. Pop an Element from a specific Stack
d. Demonstrate Overflow and Underflow situations in each stack
e. Display the status of Stack/Multi-Stack
f. Exit
Support the program with conditions for each of the above operations
2. Design, Develop and Implement a menu driven Program in C for the following operations on
Circular Singly Linked List (SLL) of Doctors Data with the fields: SSN, Name, Specialization,
Experience, PhNo.
a. Display the status of circular SLL and count the number of nodes in it.
b. Perform Insertion / Deletion at End of circular SLL.
c. Perform Insertion / Deletion at Front of circular SLL.
d. Search for a doctor with a specialization.
e. Exit
3. Design, Develop and Implement Floyd’s algorithm in C. Accept the graph representing the
distance between cities(as cost matrices) and find the shortest path from a city to all other cities
in the graph.