Professional Documents
Culture Documents
Data Structures
II Year I Semester (AR20)
(B.Tech-CSE, B.Tech-CSE (AI&ML), B.Tech-CSE (DS), B.Tech-CSE (CS), B.Tech-CSE (IOT))
Laboratory Work Book
(20CS20L01)
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING,
CSE-AIML,DS,CS & IOT
(2023-2024)
DATA STRUCTURES
LABORATORY WORKBOOK
Name :_____________________________________
CERTIFICATE
This is to certify that Mr./ Ms. _________________________________has
satisfactorily completed ________ number of experiments in the Data Structures
Laboratory.
LIST OF EXPERIMENTS
ADDITIONAL PROGRAMS
● To bring out creativity in students that would promote innovation, research and
entrepreneurship
● To Preserve and promote cultural heritage, humanistic and spiritual values promoting
peace and harmony in society
3. To facilitate graduates to get familiarized with the art software / hardware tools, imbibing
creativity and innovation that would enable them to develop cutting-edge technologies of
multi-disciplinary nature for societal development.
2. PO 2: 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.
5. PO 5: 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.
6. PO 6: 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.
8. PO 8: Ethics: Apply ethical principles and commit to professional ethics and responsibilities
and norms of the engineering practice.
11. PO 11: 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.
12. PO 12: 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..
statistical techniques to solve real world problems delivering actionable insights for
decision making.
PSO 1: Demonstrate competency in Programming and problem-solving skills and apply those
skills in solving computing problems.
PSO 2: Select appropriate programming languages, Data structures and algorithms in
combination with modern technologies and apply them in developing innovative solutions.
PSO 3: Demonstrate an ability in using IoT devices and protocols to develop IoT based
solutions for real world problems.
Course Objectives:
Develop ability to
1. Understand the basic concepts of Abstract Data Types, Linear and Non-Linear Data
structures.
2. Identify the notations used to represent the Performance of algorithms.
3. Understand the behavior of data structures such as stacks, queues, trees, hash tables, search
trees, Graphs and their representations.
4. Familiarize with various data structures for various applications.
5. Understand various searching and sorting algorithms.
6. Write programs in C to solve problems using data structures such as arrays, linked lists,
stacks, queues, trees, graphs, hash tables and search trees.
Course Outcomes:
Upon successful completion of this course, students will be able to:
CO1. Use asymptotic notation in representing space and time complexities of algorithms.
CO2. Construct different linear and non-linear data structures using array and linked
representations and use them in appropriate applications.
CO3. Implement, use and compare different sorting, searching and pattern-matching
algorithms for solving various problems.
Mapping of Course Outcomes with Program Outcomes & Program Specific Outcomes-
CSE,CSE(AI & ML), CSE (DS),CSE(CS),CSE(IOT):
POs 1 2 3 4 5 6 7 8 9 10 11 12 PS PS
O1 O2
DS Lab Exp
no.
CO1:Use 1,2,3,4 3 2 3 1 1 1 2 2 3
asymptotic ,5,6,7,
notation in 8,9,10,
representing space 11,12,
and time 13.
complexities of
algorithms.
CO2:Construct 1,2,3,4 2 2 2 3 1 1 2 2 1
different linear ,5,6,7,
and non-linear 8,9,10,
data structures 11,12,
using array and 13.
linked
representations
and use them in
appropriate
applications.
CO3:Implement, 7,8,9, 2 2 2 3 1 1 2 2 1
use and compare 10,11,
different sorting, 12,13.
searching and
pattern-matching
algorithms for
solving various
problems.
Prerequisites:
20CS11L1 Programming for Problem Solving-I LAB
1. Observation book and lab records submitted for the lab work are to be checked and
signed before the next lab session.
2. Students should be instructed to switch ON the power supply after the connections
are checked by the lab assistant / teacher.
3. The promptness of submission should be strictly insisted by awarding the marks
accordingly.
4. Ask Discussion Topics at the end of the experiment.
5. Do not allow students who come late to the lab class.
6. Encourage the students to do the experiments innovatively.
7. Fill continuous Evaluation sheet, on regular basis.
8. Ensure that the students are dressed in formals.
2) Experiment/program------------------------------- 15 Marks
INDEX
Date of
Date of Mark Signatur Rema
S.No Name of Experiment Submis
Exp. s e rks
sion
INDEX
Date of
Date of Mark Signatur Rema
S.No Name of Experiment Submis
Exp. s e rks
sion
WEEK 1 Date:
Write a C program for polynomial addition using linked lists.
Objectives:
Student will able to learn the practical application of linear list.
ALGORITHM/PSEUDOCODE:
Step 1: Start
Step 2: Let p and q be the two polynomials represented by the linked list.
Step 3: While p and q are not null, repeat step 2.
Step 4: Sort both polynomial
Step 5: If powers of the two terms are equal then if the terms do not cancel then insert the sum of
the terms into the sum Polynomial
Step 5.1: Advance p
Advance q
Step 5.2: Else if the power of the first polynomial> power of second
Step 4.2.1: Then insert the term from first polynomial into sum polynomial
Step 4.2.2: Advance p
Step 5.3: Else insert the term from second polynomial into sum polynomial
Advance q
Step 6: Copy the remaining terms from the non empty polynomial into the sum polynomial
Step 7: Stop.
Input Output
Outcomes:
The student will be able to understand the requirements of a mathematical problem and develop
a solution using appropriate data structure.
DISCUSSION TOPICS
2. What are the reasons for choosing linked list to solve polynomial addition?
WEEK 2 Date:
Objectives:
Student will able to learn the implementation of circularly linked list Data structure.
ALGORITHM/PSEUDOCODE:
Step 1: Start
Step 2: Creation: Get the number of elements, and create the nodes having fields DATA and
LINK and store the element in Data field, link them together to form a linked list where the
last node always contains the address of first node .
Step 3: Insertion: Get the number to be inserted and create a new node, store the value in
DATA field. And insert the node in the required position .If it is last node make sure it
contains the address of first node.
Step 4: Deletion: Get the number to be deleted. Search the list from the beginning and locate
the node then delete the node.
Step 5: Display: Display all the nodes in the list.
Step 6: Stop.
Input Output
Outcomes:
DISCUSSION TOPICS
WEEK 3 Date:
Objectives:
Student will able to learn the implementation of doubly linked list Data structure.
ALGORITHM/PSEUDOCODE:
Step 5 -Keep moving thetemp1to its next node until it reaches to the node after which we want to insert the newN
Step 6 - Every time check whether temp1 is reached to the last node. If it is reached to the last
node then display 'Given node is not found in the list!!! Insertion not possible!!!' and terminate
the function. Otherwise move the temp1 to next node.
Step 7 -Assigntemp1 nexttotemp2,newNodetotemp1 next,temp1tonewNode previous,temp2tonewNode nextan
Step 6 -Finally, displaytemp datawith arrow pointing toNULL(temp data ---> NULL).
Input Output
Outcomes:
Student gains the ability
● To understand the doubly linked list Data structure.
DISCUSSION TOPICS
2. What the difference is between singly linked and doubly linked list?
3. List the advantages of doubly linked list over singly linked list?
WEEK 4: Date:
Write C programs to implement a Stack and Queue ADT using Singly Linked List.
Objectives:
Student will able to learn the explicit implementation of lists namely Stack and Queue.
Algorithm: Stack Using Linked List
To implement stack using linked list, we need to set the following things before implementing
actual operations.
Step 1: Include all the header files which are used in the program. And declare all the user
defined functions.
Step 2: Define a 'Node' structure with two members data and next.
Step 3: Define a Node pointer 'top' and set it to NULL.
Step 4: Implement the main method by displaying Menu with list of operations and make
suitable function calls in the main method.
Step 4: Display 'temp data --->' and move it to the next node. Repeat the same until temp reaches to the first nod
Program
Input Output
Step 1: Include all the header files which are used in the program. And declare all the user
defined functions.
Step 2: Define a 'Node' structure with two members data and next.
Step 3: Define two Node pointers 'front' and 'rear' and set both to NULL.
Step 4: Implement the main method by displaying Menu of list of operations and make suitable
function calls in the main method to perform user selected operation.
Program
Input Output
Outcomes:
Student will be able to use the knowledge gained through generic implementation of Linked list
and apply it to Stack and Queue operations.
DISCUSSION TOPICS
1. What is the principle of stack?
3. Explain the difference between stack using array and linked list?
WEEK 5 : Date:
Write a C program to implement the following:
a) Towers of Hanoi.
b) Parenthesis Checker (by using stack ).
Objectives:
Student will learn about practical implementation of Stack ADT.
A. Algorithm/Pseudocode: Towers of Hanoi
Start
Procedure Hanoi(n, disk, source, aux)
If disk=1 then
Move disk from source to dest
Else
Hanoi(disk-1,source,aux,dest)
Move disk from source to dest
Hanoi(disk-1,aux,dest,source)
END IF
Program:
Input Output
Input Output
Outcomes:
Student gains the knowledge to solve and implement an application using stack ADT.
DISCUSSION TOPICS
1. What is polish notation?
WEEK 6: Write a C program to implement Circular Queue using array and linked list.
Objectives:
Student will learn about practical implementation of Queue ADT.
3. Check if (front==rear) if it is true then set front = rear = NULL else move the front
forward in queue, update address of front in rear node and return the element.
Program
Input Output
Outcomes:
Student gains the knowledge to understand the Circularly Queue Data structure.
DISCUSSION TOPICS
1. Explain the necessity of circular queue.
WEEK 7: Date:
Write C programs to implement a double ended queue ADT using linked list.
Objectives:
Student will learn to implement doubly linked list.
Algorithm/Pseudocode:
Algorithm for Insertion at rear end
1. Allocate space for a newnode of doubly linked list
2.if newnode == NULL then
print "Overflow"
3.else
if rear == NULL, then
rear = front = newnode
else
newnode->prev = rear
rear->next = newnode
rear = newnode
PROGRAM:
Input Output
Outcomes:
Student gains the knowledge of double ended queue ADT and can implement it using array or
linked list.
DISCUSSION TOPICS
1. Explain the necessity of double ended queue.
WEEK 8:
a) Create a binary search tree of integers.
b) Traverse the above Binary search tree in in-order, pre-order, post-order.
Objectives:
Student will learn non-linear data structures with the implementation of Binary-Tree.
Input Output
Outcomes:
Student will be able to create and perform various traversal algorithms on a Binary Tree.
DISCUSSION TOPICS
1. What is binary tree?
WEEK 9:
Write C programs for implementing the following sorting methods to arrange a list of integers in
ascending order:
a) Merge sort b) Heap sort
Objectives:
Student will learn some of the algorithms to sort given data.
Merge sort
Algorithm/PSEUDOCODE:
Step 1: Start
Step 2: Create the variables and an array
Step 3: Print the elements enter by keyboard by for loop
Step 4: Call the function merge sort
Step 5: Initialize the variables
Step 6: if list size is 0(empty) or 1, consider it sorted and return it
Step 7: Using less than or equal prevents infinite recursion for a 0 length m
Step 8: if length(m) <= 1 then return m
PROGRAM:
Input Output
b) Heap sort
ALGORITHM/PSEUDOCODE:
Step 5: Implementations require two arrays - one to hold the heap and the other to hold the sorted
elements.
PROGRAM:
Input output
Outcomes:
Student gains the knowledge to implement different sorting techniques on given list of elements.
a) Merge sort b)Heap sort
DISCUSSION TOPICS
1. What is the advantage of merge sort?
WEEK 10 Date:
Write C programs for implementing the following sorting methods to arrange a list of integers in
ascending order:
a) Radix sort b) Binary Insertion sort
Objectives:
Student will learn some of the algorithms to sort given data.
Radix sort
Radix Sort is an algorithm that sorts a list of numbers and comes under the category of
distribution sort.
This sorting algorithm doesn't compare the numbers but distributes them, it works as follows:
ALGORITHM
Step 1: Sorting takes place by distributing the list of number into a bucket by passing through the
individual digits of a given number one-by-one beginning with the least significant part. Here,
the number of buckets are a total of ten, which bare key values starting from 0 to 9.
Step 2: After each pass, the numbers are collected from the buckets, keeping the numbers in
order
Step 3: Now, recursively redistribute the numbers as in the above Step '1' but with a following
reconsideration: take into account next most significant part of the number, which is then
followed by above Step '2'.
PROGRAM:
Input Output
ALGORITHM
Step 1: Iterate the array from the second element to the last element.
Step 3: Find the position of the element just greater than A[i] in the subarray from A[0] to A[i-
1] using binary search. Say this element is at index pos.
Step 4: Shift all the elements from index pos to i-1 towards the right.
Program
Input Output
Outcomes:
Student gains the knowledge to implement different sorting techniques on given list of elements.
a) Radix sort b) Binary insertion sort
DISCUSSION TOPICS
1. Show the importance of Radix sort?
WEEK 11 Date:
Write a C program to perform the following operation:
a) Insertion into a B-tree. b) Searching a B-Tree.
Algorithm/Pseudocode:
Step 1: Start
Step 2: Create a structure
Step 3: Create a new node
Step 4: Places the value in appropriate position
Step 5: Split the node
Input Output
Outcomes:
Student gains the knowledge to implement operations on a B Tree
DISCUSSION TOPICS
1. List the efficient search trees available in Data Structures?
WEEK 12 Date:
Write C programs for implementing the following graph traversal algorithms:
a) Depth first traversal. b) Breadth first traversal.
Objectives:
Student will learn about graph traversal algorithms.
Algorithm for DFS
1. Start at some node ‘i’. This is now our current node.
2. State that our current node is ‘visited’.
3. Now look at all nodes adjacent to our current node.
4. If we see an adjacent node that has not been ‘visited’, add it to the stack.
5. Then pop of the top node on the stack and traverse to it.
6. And go back to step 1.
This algorithm terminates when all nodes have been visited, the stack is empty.
Program:
Input Output
4. If we see an adjacent node that has not been ‘visited’, add it to the queue.
5. Then pull out the first node on from the queue and traverse to it.
6. And go back to step 1.
Program:
Input Output
Outcomes:
Student gains the knowledge to implement graph traversal algorithms.
DISCUSSION TOPICS
1. Define graph with respect to Data structures in C?
WEEK 13 Date:
Write a C program to implement all the functions of a dictionary (ADT) using hashing.
Objectives:
Student will learn about concept of Hashing.
ALGORITHM:
Step1:Start
Step2:initialize the variables
Step3:create structure
Step4:Enter number of elements
Step5:read ch value if
Case1-insertion
Case2-deletion
Case3- searching
Case4- display
Case5-exit
Step6: :Select case 1 for insertion perform
void insertInHash(int key, char *name, int age) {
int hashIndex = key % tableSize;
if (tableSize == totEle) {
printf("Can't perform Insertion..Hash Table is full!!");
return;
}
while (hashTable[hashIndex].marker == 1) {
hashIndex = (hashIndex + 1)%tableSize;
}
hashTable[hashIndex].key = key;
hashTable[hashIndex].age = age;
strcpy(hashTable[hashIndex].name, name);
hashTable[hashIndex].marker = 1;
totEle++;
return;
}
Step7:Select case2 for deletion as
Program:
Input Output
Outcomes:
Student gains the knowledge to implement all the functions of a dictionary (ADT) using hashing.
DISCUSSION TOPICS
1. Explain hashing?
WEEK 14 Date:
Write a C program for pattern matching using Knuth-Morris-Pratt algorithm.
Objectives:
Student will learn about pattern matching algorithm (KMP).
ALGORITHM:
PROGRAM:
Input Output
Outcomes:
Student gains the knowledge to implement pattern matching algorithm (KMP).
DISCUSSION TOPICS
1. What is pattern matching?
ADDITIONAL PROGRAMS
Input Output
Input Output
3. Write a C program to merge of the contents of a two Singly linked list and display in sorted
order.
Input Output
Input Output