DSA Lab Manual 1 2 3
DSA Lab Manual 1 2 3
LABORATORY MANUAL
SEMESTER : III
SUBCODE : BCSL305
NAME: ____________________________________________________________
USN: _____________________________________________________________
SECTION: __________________________________________________________
BATCH: ___________________________________________________________
DATA STRUCTURES LABORATORY (BCSL305) 2023-2024
PROGRAM OUTCOMES
Engineering Graduates will able to:
Engineering knowledge: Apply the knowledge of mathematics, science, engineering fundamentals, and
an engineering specialization to the solution of complex engineering problems.
Problem analysis: Identify, formulate, review research literature, and analyze complex engineering
problems reaching substantiated conclusions using first principles of mathematics, natural sciences, and
engineering sciences.
Design/development of solutions: Design solutions for complex engineering problems and design system
components or processes that meet the specified needs with appropriate consideration for the public
health and safety, and the cultural, societal, and environmental considerations.
Conduct investigations of complex problems: Use research-based knowledge and research methods
including design of experiments, analysis and interpretation of data, and synthesis of the information to
provide valid conclusions.
Modern tool usage: Create, select, and apply appropriate techniques, resources, and modern engineering
and IT tools including prediction and modelling to complex engineering activities with an understanding
of the limitations.
The engineer and society: Apply reasoning informed by the contextual knowledge to assess societal,
health, safety, legal and cultural issues and the consequent responsibilities relevant to the professional
engineering practice.
Environment and sustainability: Understand the impact of the professional engineering solutions in
societal and environmental contexts, and demonstrate the knowledge of, and need for sustainable
development.
Ethics: Apply ethical principles and commit to professional ethics and responsibilities and norms of the
engineering practice. Individual and team work: Function effectively as an individual, and as a member or
leader in diverse teams, and in multidisciplinary settings.
Individual and Team Work: Function effectively as an individual, and as a member or leader in diverse
teams, and in multidisciplinary settings.
Project management and finance: Demonstrate knowledge and understanding of the Engineering and
management principles and apply these to one’s own work, as a member and leader in a team, to manage
projects and in multidisciplinary environments.
Life -long learning: Recognize the need for and have the preparation and ability to engage in independent
and life -long learning in the broadest context of technological change.
DATA STRUCTURES LABORATORY (BCSL305) 2023-2024
The East Point College of Engineering and Technology aspires to be a globally acclaimed
institution, recognized for excellence in engineering education, applied research and nurturing
students for holistic development.
MISSION
M1: To create engineering graduates through quality education and to nurture innovation,
creativity and excellence in teaching, learning and research
M2: To serve the technical, scientific, economic and societal developmental needs of our
communities
M3: To induce integrity, teamwork, critical thinking, personality development and ethics in
students and to lay the foundation for lifelong learning
DATA STRUCTURES LABORATORY (BCSL305) 2023-2024
To be the foremost innovator and leader in the field of IoT and Cyber security, driving the
evolution of secure and connected technologies, ensuring the trust and safety of digital
ecosystems worldwide.
MISSION
M1: We are dedicated to advancing digital trust by pioneering cutting-edge solutions that
secure IoT devices, networks, and data, guaranteeing the reliability and privacy of the
connected world.
M2: Our mission is to continuously innovate and develop robust cyber security technologies
that proactively anticipate and counter emerging threats, fostering a secure environment for IoT
applications.
M3: We are committed to educating and empowering businesses, individuals, and communities
through extensive training and awareness programs, equipping them with the knowledge to
defend against cyber threats.
DATA STRUCTURES LABORATORY (BCSL305) 2023-2024
PEO 1: Graduates will have successful careers in IoT and Cybersecurity or related fields,
demonstrating expertise and leadership in securing and managing interconnected systems.
PEO 2: Graduates will engage in lifelong learning and professional development, staying
current with evolving technologies and security threats to adapt to changing industry demands.
PEO 3: Graduates will possess the skills to analyze and solve complex IoT and cybersecurity
challenges, applying critical thinking, ethical decision-making, and innovative approaches.
PSO 1: Graduates will be proficient in understanding, configuring, and securing IoT devices,
networks, and platforms, including familiarity with IoT protocols and technologies.
PSO 2: Graduates will have expertise in securing IoT devices, including hardware security,
firmware integrity, and encryption of data at rest and in transit.
PSO 3: Graduates will possess the skills to conduct digital forensics investigations in IoT
environments to trace and analyze security incidents.
COURSE OUTCOMES
CO1: Analyze various linear and non-linear data structures.
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.
DATA STRUCTURES AND APPLICATIONS
[As per Choice Based Credit System (CBCS) scheme]
(Effective from the academic year 2023-2024)
SEMESTER – III
Course Code BCSL305 CIE Marks 50
Number of Lecture Hours/Week 0:0:2 SEE Marks 50
Total Number of Lecture Hours 28
CREDITS – 01
Course Learning Objectives:
This laboratory course enables students to get practical experience in design, develop,
implement, analyze and evaluation/testing of
Prerequisite
Sl.No List of problems for which student should develop program and execute in the
Laboratory
1 Aim: Demonstrate Creation and Display of array of structures
Program: 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.
2 Aim: Demonstrate the string Operations
Program: 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.
3 Aim: Implement stack operations
Program: Develop 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 how Stack can be used to check Palindrome
d. Demonstrate Overflow and Underflow situations on Stack
e. Display the status of Stack
f. Exit
Support the program with appropriate functions for each of the above operations
4 Aim: Implement the applications of stack
Program: Develop 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
5 Aim: Implement the applications of stack
Program: Design, Develop and Implement a Program in C for the following Stack
Application
a. Evaluation of Suffix expression with single digit operands and operators: +, -, *, /, %, ^
b. Solving Tower of Hanoi problem with n disks
Course Outcomes
At the end of the course the student will be able to:
Reference Books:
1. Seymour Lipschutz, Data Structures Schaum's Outlines, Revised 1st Ed, McGraw Hill, 2014.
2. Reema Thareja, Data Structures using C, 3rd Ed, Oxford press, 2012
3. Gilberg and Forouzan, Data Structures: A Pseudo-code approach with C, 2nd Ed, Cengage
Learning,2014.
4. Jean-Paul Tremblay & Paul G. Sorenson, An Introduction to Data Structures with Applications,2nd
Ed, McGraw Hill, 2013
5. A M Tenenbaum, Data Structures using C, PHI, 1989
6. Robert Kruse, Data Structures and Program Design in C, 2nd Ed, PHI, 1996.
● http://elearning.vtu.ac.in/econtent/courses/video/CSE/06CS35.html
● https://nptel.ac.in/courses/106/105/106105171/
● http://www.nptelvideos.in/2012/11/data-structures-and-algorithms.html
● https://www.youtube.com/watch?v=3Xo6P_V-qns&t=201s
● https://ds2-iiith.vlabs.ac.in/exp/selection-sort/index.html
● https://nptel.ac.in/courses/106/102/106102064/
● https://ds1-iiith.vlabs.ac.in/exp/stacks-queues/index.html
● https://ds1-iiith.vlabs.ac.in/exp/linked-list/basics/overview.html
● https://ds1-iiith.vlabs.ac.in/List%20of%20experiments.html
● https://ds1-iiith.vlabs.ac.in/exp/tree-traversal/index.html
● https://ds1-iiith.vlabs.ac.in/exp/tree-traversal/depth-first-traversal/dft-practice.html
● https://infyspringboard.onwingspan.com/web/en/app/toc/lex_auth_013501595428077568125 59/overview
Conduct of Practical Examination:
Experiment distribution
Students are allowed to pick one experiment from the lot with equal opportunity.
Change of experiment is allowed only once and marks allotted for procedure to be made zero of
the changed part only.
Data Structure is defined as the way in which data is organized in the memory
14
Data Structures Laboratory – BCSL305 III Semester / B.E.
EXPERIMENT - 01
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.
ALGORITHM:
Step 1: Create a structure to represent day.
Step 2: Read data for the calendar.
Step 3: Display the weekly activity report
Step 4: Stop.
PROGRAM CODE:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
15
Data Structures Laboratory – BCSL305 III Semester / B.E.
int main()
{
int weekSize = 7;
struct Day calendar[weekSize];
// Create the calendar
read(calendar, weekSize);
// Display the weekly activity details
display(calendar, weekSize);
// Free dynamically allocated memory
for (int i = 0; i < weekSize; i++)
{
free(calendar[i].name);
free(calendar[i].activity);
}
return 0;
}
Sample Output
Enter the day name: Monday
Enter the date: 161023
Enter the activity for the day: Reading
Enter the day name: Tuesday
Enter the date: 171023
Enter the activity for the day: Coding
Enter the day name: Wednesday
Enter the date: 181023
Enter the activity for the day: Painting
Enter the day name: Thursday
Enter the date: 191023
16
Data Structures Laboratory – BCSL305 III Semester / B.E.
Day 2: Tuesday
Date: 171023
Activity: Coding
Day 3: Wednesday
Date: 181023
Activity: Painting
Day 4: Thursday
Date: 191023
Activity: playing
Day 5: Friday
Date: 201023
Activity: shopping
Day 6: Saturday
Date: 211023
Activity: Watching Movie
Day 7: Sunday
Date: 221023
Activity: Completing Assignments
17
Data Structures Laboratory – BCSL305 III Semester / B.E.
EXPERIMENT - 02
Design, Develop and Implement 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. Repost 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.
If you follow the rule of array initialization then you can write the above statement as follows:
C language supports a wide range of built-in functions that manipulate null-terminated strings as
follows:
ALGORITHM:
Step 1: Start.
Step 2: Read main string STR, pattern string PAT and replace string REP.
Step 3: Search / find the pattern string PAT in the main string STR.
Step 4: if PAT is found then replace all occurrences of PAT in main string STR with REP
string. Step 5: if PAT is not found give a suitable error message.
Step 6: Stop.
PROGRAM CODE:
#include<stdio.h>
#include<conio.h>
//Declarations
char str[100], pat[50], rep[50],
ans[100];int i, j, c, m, k, flag=0;
void stringmatch()
{
i = m = c = j = 0;
18
Data Structures Laboratory – BCSL305 III Semester / B.E.
while(str[c] ! = '\0')
{
if(str[m] = = pat[i]) // .......matching
{
i++; m++;
if(pat[i] = = '\0') //.... found occurrences.
{
flag = 1;
// .... copy replace string in ans string.
for(k = 0; rep[k] != '\0'; k++, j++)
ans[j] = rep[k];
i = 0;
c = m;
}
} // if ends.
else //... mismatch
{
ans[j] = str[c];
j++; c++;
m = c; i = 0;
}//else ends
} //end of while ans[j] = '\0';
} //end stringmatch()
void main()
{
clrscr();
printf("\nEnter a main string \n"); ]
gets(str);
printf("\nEnter a pattern string \n");
flushall();
gets(pat);
printf("\nEnter a replace string \n");
flushall();
gets(rep);
stringmatch();
if(flag = = 1)
printf("\nThe resultant string is\n %s" , ans);
else
printf("\nPattern string NOT found\n");
getch();
} // end of main
SAMPLE OUTPUT:
RUN 1:
Enter a main string
Test
Enter a pattern string
Te
Enter a replace string
Re
19
Data Structures Laboratory – BCSL305 III Semester / B.E.
RUN 2:
Enter a main string
This is Data Structure lab
Enter a pattern string
Data Structure
Enter a replace string
Data structure with C
20
Data Structures Laboratory – BCSL305 III Semester / B.E.
EXPERIMENT - 03
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 how stack can be used to check palindrome.
d. Demonstrate Overflow and Underflow situations on stack.
e. Display the status of stack.
f. Exit.
Support the program with appropriate functions for each of the above operations.
A real-world stack allows operations at one end only. For example, we can place or remove a card or plate
from top of the stack only. Likewise, Stack ADT allows all data operations at one end only. At any given time,
we can only access the top element of a stack.
This feature makes it LIFO data structure. LIFO stands for Last-in-first-out. Here, the element which is
placed (inserted or added) last is accessed first. In stack terminology, insertion operation is called
PUSH operation and removal operation is called POP operation.
A stack can be implemented by means of Array, Structure, Pointer and Linked-List. Stack can either be
a fixed size one or it may have a sense of dynamic resizing. Here, we are going to implement stack using arrays
which makes it a fixed size stack implementation.
Basic Operations:
push() - pushing (storing) an element on the stack.
pop() - removing (accessing) an element from the stack.
To use a stack efficiently we need to check status of stack as well. For the same purpose, the following
functionality is added to stacks;
. isFull() − check if stack is full.
isEmpty()-check if stack is empty
21
Data Structures Laboratory – BCSL305 III Semester / B.E.
ALGORITHM:
Step 1: Start.
Step 2: Initialize stack size MAX and top of stack -1.
Step 3: Push integer element on to stack and display the contents of the stack. if stack is full give a message as ‘Stack is
Overflow’.
Step 4: Pop element from stack along with display the stack contents. if stack is empty give a message as ‘Stack is
Underflow’.
Step 5: Check whether the stack contents are Palindrome or not.
Step 6: Stop.
PROGRAM CODE
#include<stdio.h>
#include<string.h>
#include<conio.h>
#define max 5
int st[max],top=-1;
void push(),disp(),palin();
int pop();
void main()
{
int ch,k,item; clrscr();
while(1)
{
printf("MAIN MENU\n");
printf(" 1:Push\n 2:Pop\n 3:Display\n 4:Palindrome\n 5:Exit\n");
printf("Enter your choice\n");
scanf("%d",&ch);
switch(ch)
{
case 1:printf("Enter an item to push\n");
scanf("%d",&item);
push(item);
break;
case 2: k=pop();
if(k)
printf("popped element is %d\n",k);
break;
case 3:disp();
break;
case 4:palin();
break;
case 5:exit(0);
}
}
}
void push(int item)
{
if(top==max-1)
{
printf("Stack overflow\n");
return ;
}
22
Data Structures Laboratory – BCSL305 III Semester / B.E.
st[++top]=item;
}
int pop()
{
if(top==-1)
{
printf("Stack underflow\n");return 0;
}
return(st[top--]);
}
void palin()
{
int i;
char p[100];top=-1;
printf("Enter a number to check for palindrome\n");
fflush(stdin);
gets(p);
for(i=0;i<strlen(p);i++)
push(p[i]-'0');
for(i=0;i<strlen(p)/2;i++)
if((p[i]-'0')!=pop())
{
printf("the number is not palindrome\n");
return;
}
printf("the number is palindrome\n");
}
void disp()
{
int i;
if(top==-1)
{
printf("Stack Empty\n");
return;
}
printf(“the stack contents are”);
for(i=top;i>=0;i--)
printf("|%d|\n",st[i]);
}
}
SAMPLE OUTPUT:
----MAIN MENU----
1.PUSH
2 POP
3.DISPLAY
4.PALINDROME
5.EXIT
23
Data Structures Laboratory – BCSL305 III Semester / B.E.
----MAIN MENU----
PUSH
POP
3.DISPLAY
4.EXIT
----MAIN MENU----
1. PUSH
2. POP
3.DISPLAY
4. PALINDROME
4. EXIT
Ener Your Choice: 3
Stack contents are
|4|
|3|
|2|
|1|
----MAIN MENU----
1. PUSH
2. POP
3.DISPLAY
4. PALINDROME
4. EXIT
Ener Your Choice: 2
Poped element is: 4
----MAIN MENU----
1. PUSH
2. POP
3.DISPLAY
4. PALINDROME
4. EXIT
Enter Your Choice: 2
Stack is Underflow
----MAIN MENU----
1.PUSH
2.POP
3.DISPLAY
4.PALINDROME
5.EXIT
Enter Your Choice: 4
Enter the number to check for palindrome:121
The number is palindrome
24
Data Structures Laboratory – BCSL305 III Semester / B.E.
---MAIN MENU----
1. PUSH
2. POP
3.DISPLAY
3. PALINDROME
4. EXIT
Enter Your Choice: 4
Enter the number to check for palindrome:123
The number is not palindrome
25
Data Structures Laboratory – BCSL305 III Semester / B.E.
EXPERIMENT - 04
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.
26