Data Structures Lab Manual 2021-22
Data Structures Lab Manual 2021-22
• To craft students to be competent professionals with value based education, innovative teaching
and practices.
• To enhance student‘s soft skill, personality and ethical responsibilities by augmenting in- plant
training, value added courses and co curricular activities.
• To facilitate the student as researchers by widening their professional knowledge through continuous
learning and innovative projects.
• To produce dynamic entrepreneur through interaction with network of alumni industry and academia
and extracurricular activities.
• PEO1:Graduates will apply engineering basics, laboratory and job oriented experiences to devise and
unravel engineering problems in computer science engineering domain.
• PEO2:Graduates will be multi faceted researcher and experts in fields like computing, networking,
artificial intelligence, software engineering and data science.
• PEO3:Graduates will be dynamic entrepreneur and service oriented professional with ethical and social
responsibility.
• PEO4:Graduates will ingress and endure in core and other prominent organization across the globe
and will foster innovation
PSO-I: The ability to understand, analyze and to develop the design related to real-time system such as
IOT, Secured automated systems, machine vision , computer vision and cognitive computing with
various complexities , providing orientation towards green computing environment .
PSO-II: The ability to apply standard practices and strategies in software project development using
open-ended programming environments to deliver a quality product.
PSO-III: The ability to innovate, introduce and produce socially relevant products to facilitate
transformation of society into a digitally empowered knowledge economy, thereby to chart a successful
career with a new dimension to entrepreneurship.
JERUSALEM COLLEGE OF ENGINEERING
(An Autonomous Institution)
(Approved by AICTE, Affiliated to Anna University
Accredited by NBA and NAAC with ‘A’ Grade)
Velachery Main Road, Pallikaranai , Chennai – 600100
Name……………………………………………………………………………………
Year…………………………………Semester………………Branch……………….
Regulation………………..
Register No.
Certified that this is a Bonafide Record work done by the above student in the
EXAMINERS
DATE:
SYLLABUS
L T P C
JCS1311 DATA STRUCTURES LABORATORY
0 0 4 2
COURSE OBJECTIVES
• To implement linear and non-linear data structures
• To identify and implement appropriate data structures for various applications
• To execute different operations of search trees
• To implement various sorting and searching algorithms
• To implement hashing techniques
LIST OF PROGRAMS
Implement the following programs
1. List ADT using Python with insert, delete, search and modify operations
2. Linked list
3. Polynomial Manipulation using list ADT
4. Stack using Python
5. a. Stack ADT using arrays
b. Stack ADT using linked list
6. a. Queue ADT using arrays
b. Queue ADT using linked list
7. Infix to Postfix conversion
8. Circular queue
9. Binary Search Trees and Tree traversals
10. AVL Trees
11. BFS and
12. DFS of a graph
13. Bubble sort,
14. Selection sort,
15. Insertion sort using Python
16. Linear search and
17. Binary search using Python
18. Hashing-Linear Probing and
19. Quadratic Probing
TOTAL 60 Periods
COURSE OUTCOMES
Upon completion of the course, the students will be able to:
1. Identify appropriate data structures for specified problem definition
2. Implement operations like searching, insertion, deletion, traversing mechanism etc. on
various data structures
3. Apply appropriate linear / non -linear data structure operations for solving a given problem
4. Implement appropriate sorting/searching technique for given problem
5. Apply appropriate hash functions that result in a collision free scenario for data storage and
retrieval
1
JCS1311/DATA STRUCTURES LAB DEPARTMENT OF CSE 2021-22
LIST OF EXPERIMENTS
CYCLE 1
8. Circular queue
CYCLE 2
2
JCS1311/DATA STRUCTURES LAB DEPARTMENT OF CSE 2021-22
CONTENTS
3
JCS1311/DATA STRUCTURES LAB DEPARTMENT OF CSE 2021-22
CONTENTS
Average Marks :
Signature :
4
JCS1311/DATA STRUCTURES LAB DEPARTMENT OF CSE 2021-22
Exp. No:1
LIST ADT USING ARRAY IN PYTHON WITH INSERT, DELETE,
Date: SEARCH AND MODIFY OPERATIONS
AIM :
ALGORITHM:
Basic Operations:
1. Is Empty(LIST)
2. Is Full(LIST)
3. Insert Element to End of the LIST.
4. Delete Element from End of the LIST.
5. Insert Element to front of the LIST.
6. Delete Element from front of the LIST.
7. Insert Element to nth Position of the LIST.
8. Delete Element from nth Position of the LIST.
9. Search Element in the LIST.
10. Print the Elements in the LIST.
1. Is Empty(LIST):
If (Current Size==0) "LIST is Empty"
2. Is Full(LIST):
If (Current Size=Max Size) "LIST is FULL"
else "LIST is not FULL"
6
JCS1311/DATA STRUCTURES LAB DEPARTMENT OF CSE 2021-22
7
JCS1311/DATA STRUCTURES LAB DEPARTMENT OF CSE 2021-22
8
JCS1311/DATA STRUCTURES LAB DEPARTMENT OF CSE 2021-22
9
JCS1311/DATA STRUCTURES LAB DEPARTMENT OF CSE 2021-22
10
JCS1311/DATA STRUCTURES LAB DEPARTMENT OF CSE 2021-22
11
JCS1311/DATA STRUCTURES LAB DEPARTMENT OF CSE 2021-22
Exp. No:2
LIST ADT USING LINKED LIST
Date:
AIM:
ALGORITHM:
Create:
1. first=new node;{create the 1st node of the list pointed by first}; 2.REad(Data(first));
3. NEXT(First)=NULL;
4. Far a First; [point Far to the First]
5. For I=1 to N-1 repeat steps 6 to 10
6.X=new node;
7.Read(Data(X))
8.NEXT(X)=NULL;
9.NEXT(Far)=X; {connect the nodes} 10.Far=X;[shift the
8.END
SEARCH
1.If first=NULL then{
Print “List empty”; STOP;}
STOP
}
5.ptr=NEXT (ptr); [shift ptr to the next node]
[end of while]
INSERTION
1. X=new node;
2. Read(DATA(X);
3. If (FIRST=NULL) then
{
First=X;
NEXT(X)=NULL;
}
Else
{
NEXT(X)=First;
First=X;
}
4. END
13
JCS1311/DATA STRUCTURES LAB DEPARTMENT OF CSE 2021-22
NEXT(X)=NEXT(ptr)
NEXT(ptr)=X; BREAK;
}
4. ptr=NEXT(ptr)
[end of while]
5. END
INSERT BEFORE A NODE
1. ptr=LIST
[check if the first node is the desired one]
2. If(data(ptr)=’VAL’) then
{
X=new node;
Read DATA(X);
NEXT(X)=LIST;
LIST=X;
STOP;
}
3. While(ptr<>NULL ) repeat step 4 to 6
4. back=ptr;
5. ptr=NEXT(ptr);
6. If(DATA(ptr)=’VAL’)then
{
X=new node;
Read DATA(X);
NEXT(X)=ptr;
NEXT(back)=X;
EXIT;
}
7. END
DELETING A NODE FROM A LINKED LIST
CHECK IF THE FIRST NODE IS THE DESIRED ONE]
1. If (DATA(list)=’VAL’)then
{
Ptr=LIST;
LIST=NEXT(list);
Delete ptr;
Stop;
}
Back=list;
Ptr=list;
2.While(ptr<>NULL) repeat step 3 to 5
14
JCS1311/DATA STRUCTURES LAB DEPARTMENT OF CSE 2021-22
3.If(DATA(ptr)=’VAL’) then
{
NEXT(back)=NEXT(ptr);
Delete ptr;
Exit;}
4.back=ptr;
5.ptr=next(ptr);
15
JCS1311/DATA STRUCTURES LAB DEPARTMENT OF CSE 2021-22
16
JCS1311/DATA STRUCTURES LAB DEPARTMENT OF CSE 2021-22
17
JCS1311/DATA STRUCTURES LAB DEPARTMENT OF CSE 2021-22
18
JCS1311/DATA STRUCTURES LAB DEPARTMENT OF CSE 2021-22
19
JCS1311/DATA STRUCTURES LAB DEPARTMENT OF CSE 2021-22
Exp. No:3
POLYNOMIAL MANIPULATION USING LIST ADT
Date:
AIM:-
To write a ‘C’ program to represent a polynomial as a linked list and write functions for
polynomial addition
ALGORITHM:-
20
JCS1311/DATA STRUCTURES LAB DEPARTMENT OF CSE 2021-22
21
JCS1311/DATA STRUCTURES LAB DEPARTMENT OF CSE 2021-22
22
JCS1311/DATA STRUCTURES LAB DEPARTMENT OF CSE 2021-22
23
JCS1311/DATA STRUCTURES LAB DEPARTMENT OF CSE 2021-22
24
JCS1311/DATA STRUCTURES LAB DEPARTMENT OF CSE 2021-22
Exp. No:4
STACK USING ARRAY IN PYTHON
Date:
AIM :
ALGORITHM:
Basic Operations
Push Operation
The process of putting a new data element onto stack is known as a Push Operation. Push
operation involves a series of steps
• If the stack is not full, increments top to point next empty space.
• Returns success.
25
JCS1311/DATA STRUCTURES LAB DEPARTMENT OF CSE 2021-22
Pop Operation
In an array implementation of pop() operation, the data element is not actually removed,
instead top is decremented to a lower position in the stack to point to the next value. A Pop
operation may involve the following steps −
• If the stack is not empty, accesses the data element at which top is pointing.
• Returns success.
26
JCS1311/DATA STRUCTURES LAB DEPARTMENT OF CSE 2021-22
27
JCS1311/DATA STRUCTURES LAB DEPARTMENT OF CSE 2021-22
28
JCS1311/DATA STRUCTURES LAB DEPARTMENT OF CSE 2021-22
Exp. No:5a
STACK ADT USING ARRAYS
Date:
AIM :
PROGRAM
29
JCS1311/DATA STRUCTURES LAB DEPARTMENT OF CSE 2021-22
30
JCS1311/DATA STRUCTURES LAB DEPARTMENT OF CSE 2021-22
31
JCS1311/DATA STRUCTURES LAB DEPARTMENT OF CSE 2021-22
Exp. No:5b
STACK ADT USING LINKED LIST
Date:
AIM:
ALGORITHM:
1. Include all the header files which are used in the program. And declare all the user defined
functions.
4. Implement the main method by displaying Menu with list of operations and make suitable
function calls in the main method.
We can use the following steps to insert a new node into the stack...
We can use the following steps to delete a node from the stack...
• If it is Not Empty, then define a Node pointer 'temp' and set it to 'top'.
32
JCS1311/DATA STRUCTURES LAB DEPARTMENT OF CSE 2021-22
We can use the following steps to display the elements (nodes) of a stack...
• If it is Not Empty, then define a Node pointer 'temp' and initialize with top.
• Display 'temp → data --->' and move it to the next node. Repeat the same
until temp reaches to the first node in the stack (temp → next != NULL).
33
JCS1311/DATA STRUCTURES LAB DEPARTMENT OF CSE 2021-22
34
JCS1311/DATA STRUCTURES LAB DEPARTMENT OF CSE 2021-22
35
JCS1311/DATA STRUCTURES LAB DEPARTMENT OF CSE 2021-22
Exp. No:6A
. QUEUE ADT USING ARRAYS
Date:
AIM:
ALGORITHM:
Basic Operations
• enqueue() − add (store) an item to the queue.
Enqueue Operation
• Check if the queue is full.
• If the queue is not full, increment rear pointer to point the next empty space.
• Add data element to the queue location, where the rear is pointing.
• return success.
36
JCS1311/DATA STRUCTURES LAB DEPARTMENT OF CSE 2021-22
Dequeue Operation
• Check if the queue is empty.
• If the queue is not empty, access the data where front is pointing.
• Return success.
37
JCS1311/DATA STRUCTURES LAB DEPARTMENT OF CSE 2021-22
38
JCS1311/DATA STRUCTURES LAB DEPARTMENT OF CSE 2021-22
39
JCS1311/DATA STRUCTURES LAB DEPARTMENT OF CSE 2021-22
40
JCS1311/DATA STRUCTURES LAB DEPARTMENT OF CSE 2021-22
Exp. No:6b
QUEUE ADT USING LINKED LIST
Date:
AIM:
ALGORITHM:
2. Include all the header files which are used in the program. And declare all the user
defined functions.
4. Define two Node pointers 'front' and 'rear' and set both to NULL.
5. 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.
We can use the following steps to insert a new node into the queue...
• Create a newNode with given value and set 'newNode → next' to NULL.
• If it is Not Empty then, set rear → next = newNode and rear = newNode.
We can use the following steps to delete a node from the queue...
• If it is Not Empty then, define a Node pointer 'temp' and set it to 'front'.
We can use the following steps to display the elements (nodes) of a queue...
41
JCS1311/DATA STRUCTURES LAB DEPARTMENT OF CSE 2021-22
• If it is Not Empty then, define a Node pointer 'temp' and initialize with front.
• Display 'temp → data --->' and move it to the next node. Repeat the same until 'temp'
reaches to 'rear' (temp → next != NULL).
42
JCS1311/DATA STRUCTURES LAB DEPARTMENT OF CSE 2021-22
43
JCS1311/DATA STRUCTURES LAB DEPARTMENT OF CSE 2021-22
44
JCS1311/DATA STRUCTURES LAB DEPARTMENT OF CSE 2021-22
Exp. No:7
INFIX TO POST FIX CONVERSION
Date:
AIM:-
To write a ‘C’ program to implement stack and use it to convert infix to post fix
expression.
ALGORITHM:
4. If the scanned character is an operand, add it to the Post fix string. If the scanned
character is an operator and if the stack is empty Push the character to stack.
4.1 If the scanned character is an Operand and the stack is not empty,
compare the precedence of the character with the element on top of the stack
(top Stack).
4.2 If top Stack has higher precedence over the scanned character Pop the
stack else Push the scanned character to stack. Repeat this step as long as
stack is not empty and top Stack has precedence over the character.
5. (After all characters are scanned, we have to add any character that the stack may
have to the Postfix string.) If stack is not empty add top Stack to Postfix string and
Pop the stack. Repeat this step as long as stack is not empty.
45
JCS1311/DATA STRUCTURES LAB DEPARTMENT OF CSE 2021-22
46
JCS1311/DATA STRUCTURES LAB DEPARTMENT OF CSE 2021-22
47
JCS1311/DATA STRUCTURES LAB DEPARTMENT OF CSE 2021-22
48
JCS1311/DATA STRUCTURES LAB DEPARTMENT OF CSE 2021-22
Exp. No:8
CIRCULAR QUEUE
Date:
AIM:-
ALGORITHM:
PROGRAM
50
JCS1311/DATA STRUCTURES LAB DEPARTMENT OF CSE 2021-22
51
JCS1311/DATA STRUCTURES LAB DEPARTMENT OF CSE 2021-22
52
JCS1311/DATA STRUCTURES LAB DEPARTMENT OF CSE 2021-22
53
JCS1311/DATA STRUCTURES LAB DEPARTMENT OF CSE 2021-22
Exp. No:9
BINARY SEARCH TREES AND TREE TRAVERSALS
Date:
AIM:-
ALGORITHM:-
4. Data values are given which we call a key and a binary search tree
5. To search for the key in the given binary search tree, start with the root node
6. Compare the key with the data value of the root node. If they match, return the root
pointer.
7. If the key is less than the data value of the root node, repeat the process by using
the left subtree.
8. Otherwise, repeat the same process with the right subtree until either a match is found
or the subtree under consideration becomes an empty tree.
9. Terminate
Traversal Algorithm
Algorithm Inorder(tree)
1. Traverse the left subtree, i.e., call Inorder(left-subtree)
2. Visit the root.
3. Traverse the right subtree, i.e., call Inorder(right-subtree)
54
JCS1311/DATA STRUCTURES LAB DEPARTMENT OF CSE 2021-22
Algorithm Preorder(tree)
1. Visit the root.
2. Traverse the left subtree, i.e., call Preorder(left-subtree)
3. Traverse the right subtree, i.e., call Preorder(right-subtree)
Algorithm Postorder(tree)
1. Traverse the left subtree, i.e., call Postorder(left-subtree)
2. Traverse the right subtree, i.e., call Postorder(right-subtree)
3. Visit the root.
PROGRAM:
55
JCS1311/DATA STRUCTURES LAB DEPARTMENT OF CSE 2021-22
56
JCS1311/DATA STRUCTURES LAB DEPARTMENT OF CSE 2021-22
57
JCS1311/DATA STRUCTURES LAB DEPARTMENT OF CSE 2021-22
58
JCS1311/DATA STRUCTURES LAB DEPARTMENT OF CSE 2021-22
59
JCS1311/DATA STRUCTURES LAB DEPARTMENT OF CSE 2021-22
EX.No:10
Date: IMPLEMENTATION OF AVL TREE
AIM
ALGORITHM
2. The current node must be one of the ancestors of the newly inserted node. Update the
height of the current node.
3. Get the balance factor (left subtree height – right subtree height) of the current node.
4. If balance factor is greater than 1, then the current node is unbalanced and we are either
in Left Left case or left Right case. To check whether it is left left case or not, compare
the newly inserted key with the key in left subtree root.
5. If balance factor is less than -1, then the current node is unbalanced and we are either in
Right Right case or Right Left case. To check whether it is Right Right case or not,
compare the newly inserted key with the key in right subtree root.
60
JCS1311/DATA STRUCTURES LAB DEPARTMENT OF CSE 2021-22
61
JCS1311/DATA STRUCTURES LAB DEPARTMENT OF CSE 2021-22
PROGRAM:
62
JCS1311/DATA STRUCTURES LAB DEPARTMENT OF CSE 2021-22
63
JCS1311/DATA STRUCTURES LAB DEPARTMENT OF CSE 2021-22
64
JCS1311/DATA STRUCTURES LAB DEPARTMENT OF CSE 2021-22
65
JCS1311/DATA STRUCTURES LAB DEPARTMENT OF CSE 2021-22
66
JCS1311/DATA STRUCTURES LAB DEPARTMENT OF CSE 2021-22
Exp. No:11
BREADTH FIRST SEARCH
Date:
AIM:
The aim of BFS algorithm is to traverse the graph as close as possible to the root node. Queue is
used in the implementation of the breadth first search.
Algorithm:
PROGRAM :
67
JCS1311/DATA STRUCTURES LAB DEPARTMENT OF CSE 2021-22
68
JCS1311/DATA STRUCTURES LAB DEPARTMENT OF CSE 2021-22
69
JCS1311/DATA STRUCTURES LAB DEPARTMENT OF CSE 2021-22
Exp. No:12
DEPTH FIRST SEARCH
Date:
AIM:
To represent a graph and do the BFS and DFS graph traversals for a given input graph.
The aim of DFS algorithm is to traverse the graph in such a way that it tries to go far from the
root node. Stack is used in the implementation of the depth first search.
Algorithm:
Program:
70
JCS1311/DATA STRUCTURES LAB DEPARTMENT OF CSE 2021-22
71
JCS1311/DATA STRUCTURES LAB DEPARTMENT OF CSE 2021-22
72
JCS1311/DATA STRUCTURES LAB DEPARTMENT OF CSE 2021-22
Exp. No:13
BUBBLE SORT
Date:
AIM:
ALGORITHM:
1. Starting with the first element (index = 0), compare the current element with the next
2. If the current element is greater than the next element of the array, swap them.
3. If the current element is less than the next element, move to the next element.
4. Repeat Step 1.
PROGRAM:
73
JCS1311/DATA STRUCTURES LAB DEPARTMENT OF CSE 2021-22
74
JCS1311/DATA STRUCTURES LAB DEPARTMENT OF CSE 2021-22
Exp. No:14
SELECTION SORT
Date:
AIM:
To implement the selection sort algorithm in C
ALGORITHM:
PROGRAM:
75
JCS1311/DATA STRUCTURES LAB DEPARTMENT OF CSE 2021-22
76
JCS1311/DATA STRUCTURES LAB DEPARTMENT OF CSE 2021-22
Exp. No:15
INSERTION SORT
Date:
AIM:
To implement insertion sort
ALGORITHM :
4. Shift all the elements in the sorted sub-list that is greater than the value to be sorted
PROGRAM:
77
JCS1311/DATA STRUCTURES LAB DEPARTMENT OF CSE 2021-22
78
JCS1311/DATA STRUCTURES LAB DEPARTMENT OF CSE 2021-22
Exp. No:16
LINEAR SEARCH
Date:
AIM:
ALGORITHM:
1. Traverse the array using a for loop.
2. In every iteration, compare the target value with the current value of the array.
2.1 If the values match, return the current index of the array.
2.2 If the values do not match, move on to the next array element.
PROGRAM:
79
JCS1311/DATA STRUCTURES LAB DEPARTMENT OF CSE 2021-22
80
JCS1311/DATA STRUCTURES LAB DEPARTMENT OF CSE 2021-22
Exp. No:17
BINARY SEARCH
Date:
AIM:
ALGORITHM:
PROGRAM:
81
JCS1311/DATA STRUCTURES LAB DEPARTMENT OF CSE 2021-22
82
JCS1311/DATA STRUCTURES LAB DEPARTMENT OF CSE 2021-22
83
JCS1311/DATA STRUCTURES LAB DEPARTMENT OF CSE 2021-22
Exp. No:18
Date: HASHING USING LINEAR PROBING
AIM:
ALGORITHM:
1. Start.
2. Given a File of N employee records with a set K of Keys (4-digit) which uniquely
6. Hashing as to map a given key K to the address space L, Resolve the collision (if any) is
7. Stop.
84
JCS1311/DATA STRUCTURES LAB DEPARTMENT OF CSE 2021-22
85
JCS1311/DATA STRUCTURES LAB DEPARTMENT OF CSE 2021-22
86
JCS1311/DATA STRUCTURES LAB DEPARTMENT OF CSE 2021-22
Exp. No:19
Date: HASHING USING QUADRATIC PROBING
AIM:
ALGORITHM:
87
JCS1311/DATA STRUCTURES LAB DEPARTMENT OF CSE 2021-22
88
JCS1311/DATA STRUCTURES LAB DEPARTMENT OF CSE 2021-22
89
JCS1311/DATA STRUCTURES LAB DEPARTMENT OF CSE 2021-22
90
JCS1311/DATA STRUCTURES LAB DEPARTMENT OF CSE 2021-22
Exp. No:20
DOUBLY LINKED LIST
Date:
AIM
ALGORITHM
91
JCS1311/DATA STRUCTURES LAB DEPARTMENT OF CSE 2021-22
92
JCS1311/DATA STRUCTURES LAB DEPARTMENT OF CSE 2021-22
93
JCS1311/DATA STRUCTURES LAB DEPARTMENT OF CSE 2021-22
Exp. No:21
QUICK SORT
Date:
AIM
ALGORITHM
94
JCS1311/DATA STRUCTURES LAB DEPARTMENT OF CSE 2021-22
95