Dsa Lab Manual
Dsa Lab Manual
Dsa Lab Manual
Laboratory
Experiments Manual
CSCL-2102
Semester 3rd
Fall-2022
Preface
This laboratory manual is composed of three parts. Part one provides the general information
about use in programming and gives specific information about the equipment and lab safety.
It also provides the brief information about the IDE environment like INTELLIJ. Part two
includes the laboratory experiments, problem exercises to be performed .Part three contains the
student result that is in accordance to the Lab performance, Technical knowledge, viva voce,
Assignments, Quiz, Project, its report, term and final Exams.
Introduction
The purpose of this course is to provide the students with solid foundations in the basic concepts
of programming: data structures and algorithms. The main objective of the course is to teach
the students how to select and design and implement data structures and algorithms that are
appropriate for problems that they might encounter. This course is also about showing the
correctness of algorithms and studying their computational complexities. This lab course is
designed is designed to implement of core concepts of data structures and algorithms.
LAB OBJECTIVES
Upon successful completion of this Lab course, the student should be able to:
➢ Implement various data Structures and their algorithms and apply them in implementing
simple applications..
➢ The ability to utilize logic, mathematics, and physical sciences to model and solve
➢ The ability to think critically, perform scientific analysis and develop solutions for
typical Computer Science problems.
➢ Reinforce theory and techniques taught in the class through experiments and projects
in the laboratory.
LIST OF EXPERIMENTS
S# Date Experiments Page
Introduction to Java Programming Environment, Time Complexity & 1
1
Space Complexity.
Introduction to Array, Types of Arrays, Static and Dynamic Array 8
2 Implementation and Exercises.
Sorting Algorithms including Insertion Sort, Selection Sort & Bubble 114
11 Sort Implementations in Iterative & Recursive Approach.
1 Introduction
2 ARRAYS
6 STACK
7 LINEAR QUEUE
14 AVL TREE
Remarks
Guidelines to Students
➢ Students must thoroughly read the assigned work. It will be assumed that they have
studied the assigned work and have understood the majority of the material and
technical terms before the start of the experiments.
➢ All the original data have to be recorded in a Report sheet during the laboratory
sessions. Data recording on rough sheets of papers are not allowed. In order to check
for the originality of the data, ball pen or inerasable pen should be used. If correction
has to be made, just cross it out. They must hand over the Report sheet to the
demonstrator for their signature after data count.
➢ For safety reasons, students are requested not to leave their equipment unattended
during the laboratory session. In the case of special circumstances, please seek the
support of the class teachers/demonstrators.
➢ All practical contribute to the final results of the sessional course. Thus any absent
laboratory session automatically means lost marks for the final grade. Under special
circumstances (supported by documentary proof), e.g. illness and other reasonable
causes a laboratory session may be re-scheduled upon approval of the head of the
department.
➢ During the class, students will be continuously assessed by performance test on each
and every experiment.
➢ To ensure your fellow students can proceed with their experiments in a degree of
comfort and without undue noise and other disturbances, keep the noise level down and
stay in your own laboratory bench area. Mobile phones should be switched off during
the experiments.
➢ Equipment in the laboratory for the use of student community. Students need to
maintain a proper decorum in the electronics and computer laboratories. Student must
use the equipment with care. In case of any damage, students should be pay for it.
➢ Students are required to carry their report sheet, observation books or laboratory
exercise manuals with complete exercises while entering the laboratory.
➢ Buns the CD with all Simulink home activity files and attach at the end of this manual.
Algorithm
Big O notation
1|Page
O(n)
2|Page
3|Page
O(n2)
Graph Difference
4|Page
O(n3)
5|Page
Lab Tasks:
1) Identify Runtime Complexity by making different kinds of
functions in JAVA .
2) Identify Space Complexity by making different kinds of functions
in JAVA .
3) Analyze difference between Runtime Complexity and Space
Complexity.
6|Page
Lab’s Evaluation Sheet
Students Registration No
Date Performed:
Group No:
Date of Submission
Marks /Grade
Sr. No. Categories Total Marks/Grade
Obtained
Net Result 20
7|Page
Experiment # 02
OBJECTIVE:
Introduction to Array, Types of Arrays, Static and Dynamic Array Implementation and
Exercises.
8|Page
9|Page
10 | P a g e
11 | P a g e
12 | P a g e
13 | P a g e
Exercise 1 • 1- Extend the Array class and add a new method to return the largest number. What is the
runtime complexity of this method?
• 2- Extend the Array class and add a method to return the common items in this array and another array.
14 | P a g e
• 3- Extend the Array class and add a method to return the product of Array.
• 4 - Extend the Array class and add a method to return the average of Array.
15 | P a g e
• 5 - Extend the Array class and add a method to return the reverse of Array.
• 6 - Extend the Array class and add a method to return the distinct numbers of Array.
16 | P a g e
• 7 - Extend the Array class and add a method to Replace any number from Array.
• 8 - Extend the Array class and add a method to return Even Numbers from Array.
17 | P a g e
• 9 - Extend the Array class and add a method to return ODD Numbers from Array.
• 10 - Extend the Array class and add a method to return Prime Numbers from Array.
18 | P a g e
Lab Tasks:
19 | P a g e
Lab’s Evaluation Sheet
Students Registration No
Date Performed:
Group No:
Date of Submission
Marks /Grade
Sr. No. Categories Total Marks/Grade
Obtained
Net Result 20
20 | P a g e
Experiment # 03 Introduction to Linked List, Singly
Linked List Implementation and Exercises.
Linked List
In computer science, a linked list is a linear collection of data elements whose order is not given by their
physical placement in memory. Instead, each element points to the next. It is a data structure consisting of
a collection of nodes which together represent a sequence. In its most basic form, each node contains:
data, and a reference (in other words, a link) to the next node in the sequence. This structure allows for
efficient insertion or removal of elements from any position in the sequence during iteration. More
complex variants add additional links, allowing more efficient insertion or removal of nodes at arbitrary
positions. A drawback of linked lists is that access time is linear. Faster access, is not feasible. Arrays
have better access time when compared to linked lists.
Resizing array is possible by making new array and copying data from existing array which can be
resource intensive depending on the size of array.
Inserting Data at any index in between can be difficult due to iterating over each element in array and
making room for the data by shifting existing elements in higher index within an array.
21 | P a g e
22 | P a g e
23 | P a g e
24 | P a g e
25 | P a g e
26 | P a g e
27 | P a g e
28 | P a g e
29 | P a g e
30 | P a g e
31 | P a g e
32 | P a g e
33 | P a g e
34 | P a g e
35 | P a g e
36 | P a g e
37 | P a g e
Lab Tasks:
1) Create a Program in JAVA for implementation of Singly Linked List.
2) Create a method for INSERT node at first position of Singly Linked List.
3) Create a method for Delete node from first position of Singly Linked List.
5) Create a method for INSERT node at last position of Singly Linked List.
6) Create a method for Delete node from last position of Singly Linked List.
7) Create a method for INSERT node at middle position of Singly Linked List.
8) Create a method for DELETE node from middle position of Singly Linked List.
10) Create a method to FIND MAX number from SINGLY LINKED LIST.
11) Create a method to FIND MIN number from SINGLY LINKED LIST.
38 | P a g e
Lab’s Evaluation Sheet
Students Registration No
Date Performed:
Group No:
Date of Submission
Marks /Grade
Sr. No. Categories Total Marks/Grade
Obtained
Net Result 20
39 | P a g e
Experiment # 04
OBJECTIVE:
Types of Linked List i.e Circular Linked List Implementation and Exercises.
• Any node can be a starting point. We can traverse the whole list by starting from any point. We just need
to stop when the first visited node is visited again.
• Useful for implementation of queue. Unlike this implementation, we don’t need to maintain two pointers
for front and rear if we use circular linked list. We can maintain a pointer to the last inserted node and
front can always be obtained as next of last.
• Circular lists are useful in applications to repeatedly go around the list. For example, when multiple
applications are running on a PC, it is common for the operating system to put the running applications on
a list and then to cycle through them, giving each of them a slice of time to execute, and then making
them wait while the CPU is given to another application. It is convenient for the operating system to use a
circular list so that when it reaches the end of the list it can cycle around to the front of the list.
40 | P a g e
41 | P a g e
42 | P a g e
43 | P a g e
Lab Tasks:
1) Create a Program in JAVA for implementation of Circular Linked List.
2) Create a method for INSERT node at first position of Circular Linked List.
3) Create a method for Delete node from first position of Circular Linked List.
4) Create a method for Display data from Circular Linked List.
5) Create a method for INSERT node at last position of Circular Linked List.
6) Create a method for Delete node from last position of Circular Linked List.
7) Create a method for INSERT node at middle position of Circular Linked List.
8) Create a method for DELETE node from middle position of Circular Linked List.
9) Create a method to REVERSE Circular Linked List.
10) Create a method to FIND MAX number from Circular LINKED LIST.
11) Create a method to FIND MIN number from Circular LINKED LIST.
12) Create a method to SEARCH position of data in Circular LINKED LIST.
44 | P a g e
Lab’s Evaluation Sheet
Students Registration No
Date Performed:
Group No:
Date of Submission
Marks /Grade
Sr. No. Categories Total Marks/Grade
Obtained
Net Result 20
45 | P a g e
Experiment # 05
OBJECTIVE:
Types of Linked List i.e Doubly Linked List Implementation and Exercises.
46 | P a g e
47 | P a g e
48 | P a g e
49 | P a g e
50 | P a g e
51 | P a g e
Lab Tasks:
1) Create a Program in JAVA for implementation of Doubly Linked List.
2) Create a method for INSERT node at first position of Doubly Linked List.
3) Create a method for Delete node from first position of Doubly Linked List.
4) Create a method for Display data from Doubly Linked List.
5) Create a method for INSERT node at last position of Doubly Linked List.
6) Create a method for Delete node from last position of Doubly Linked List.
7) Create a method for INSERT node at middle position of Doubly Linked List.
8) Create a method for DELETE node from middle position of Doubly Linked List.
9) Create a method to REVERSE Doubly Linked List.
10) Create a method to FIND MAX number from Doubly LINKED LIST.
11) Create a method to FIND MIN number from Doubly LINKED LIST.
12) Create a method to SEARCH position of data in Doubly LINKED LIST.
52 | P a g e
Lab’s Evaluation Sheet
Students Registration No
Date Performed:
Group No:
Date of Submission
Marks /Grade
Sr. No. Categories Total Marks/Grade
Obtained
Net Result 20
53 | P a g e
Experiment # 06
OBJECTIVE:
Introduction to Stack, Stack Implementation and Exercises Including PUSH, POP & PEEK Functions.
54 | P a g e
55 | P a g e
56 | P a g e
57 | P a g e
58 | P a g e
59 | P a g e
• 1- Create a Method to Print Max/Min value in Stack!
60 | P a g e
• Create a Function in Main Class using Stack Implementation For reversing a String.
61 | P a g e
62 | P a g e
63 | P a g e
64 | P a g e
65 | P a g e
Lab Tasks:
1) Create a program in JAVA for the implementation of STACK data structure using
Array.
13) Create a program in JAVA for the implementation of STACK data structure
using Linked List.
66 | P a g e
Lab’s Evaluation Sheet
Students Registration No
Date Performed:
Group No:
Date of Submission
Marks /Grade
Sr. No. Categories Total Marks/Grade
Obtained
3 On Time Submission 5
4 Home Activity 10
Net Result 20
67 | P a g e
Experiment # 07
OBJECTIVE:
Introduction to Queue, Linear Queue Implementation and Exercises Including ENQUEUE, DEQUEUE.
68 | P a g e
69 | P a g e
70 | P a g e
71 | P a g e
72 | P a g e
73 | P a g e
74 | P a g e
75 | P a g e
76 | P a g e
77 | P a g e
78 | P a g e
Lab Tasks:
1) Create a program in JAVA for the implementation of QUEUE data structure using
Array.
13) Create a program in JAVA for the implementation of QUEUE data structure
using Linked List.
79 | P a g e
Lab’s Evaluation Sheet
Students Registration No
Date Performed:
Group No:
Date of Submission
Marks /Grade
Sr. No. Categories Total Marks/Grade
Obtained
3 On Time Submission 5
4 Home Activity 10
Net Result 20
80 | P a g e
Experiment # 08
OBJECTIVE:
Types Of Queues including Circular Queue & Priority Queue Implementation and Exercises.
81 | P a g e
82 | P a g e
83 | P a g e
84 | P a g e
85 | P a g e
86 | P a g e
87 | P a g e
88 | P a g e
Lab Tasks:
89 | P a g e
Lab’s Evaluation Sheet
Students Registration No
Date Performed:
Group No:
Date of Submission
Marks /Grade
Sr. No. Categories Total Marks/Grade
Obtained
3 On Time Submission 5
4 Home Activity 10
Net Result 20
90 | P a g e
Experiment # 09
OBJECTIVE:
Searching Algorithms including Linear Search, Binary Search, Implementations in
Iterative & Recursive Approach.
91 | P a g e
92 | P a g e
93 | P a g e
94 | P a g e
95 | P a g e
96 | P a g e
97 | P a g e
98 | P a g e
99 | P a g e
Lab Tasks:
1)Create a function to search for Integer Data using Approach of Iterative Linear Search
Algorithm.
2)Create a function to search for Integer Data using Approach of Recursive Linear Search
Algorithm.
3)Create a function to search for Integer Data using Approach of Iterative Binary Search
Algorithm.
4)Create a function to search for Integer Data using Approach of Recursive Binary Search
Algorithm.
100 | P a g e
Lab’s Evaluation Sheet
Students Registration No
Date Performed:
Group No:
Date of Submission
Marks /Grade
Sr. No. Categories Total Marks/Grade
Obtained
3 On Time Submission 5
4 Home Activity 10
Net Result 20
101 | P a g e
Experiment # 10
OBJECTIVE:
Searching Algorithms including Ternary Search, Jump Search, Implementations.
102 | P a g e
103 | P a g e
104 | P a g e
105 | P a g e
106 | P a g e
107 | P a g e
108 | P a g e
109 | P a g e
110 | P a g e
111 | P a g e
Lab Tasks:
1)Create a function to search for Integer Data using Approach of Iterative Ternary
Search Algorithm.
2)Create a function to search for Integer Data using Approach of Recursive Ternary
Search Algorithm.
3)Create a function to search for Integer Data using Approach of Iterative Jump
Search Algorithm.
4)Create a function to search for Integer Data using Approach of Recursive Jump
Search Algorithm.
112 | P a g e
Lab’s Evaluation Sheet
Students Registration No
Date Performed:
Group No:
Date of Submission
Marks /Grade
Sr. No. Categories Total Marks/Grade
Obtained
Net Result 20
113 | P a g e
Experiment # 11
OBJECTIVE:
Sorting Algorithms including Insertion Sort, Selection Sort & Bubble Sort Implementations in Iterative &
Recursive Approach.
114 | P a g e
115 | P a g e
116 | P a g e
117 | P a g e
118 | P a g e
119 | P a g e
120 | P a g e
121 | P a g e
122 | P a g e
123 | P a g e
124 | P a g e
Lab Tasks:
1)Create a function to sort Integer Array which should be taken as Input from user by using Scanner class
object then sort in (Ascending) Order by using Approach of (Iterative Selection Sort Algorithm).
2)Create a function to sort Integer Array which should be taken as Input from user by using Scanner class
object then sort in (
3)Create a function to sort Integer Array which should be taken as Input from user by using Scanner class
object then sort in (Descending) Order by using Approach of (Iterative Selection Sort Algorithm).
4)Create a function to sort Integer Array which should be taken as Input from user by using Scanner class
object then sort in ( Descending ) Order by using Approach of (Recursive Selection Sort Algorithm).
5)Create a function to sort Integer Array which should be taken as Input from user by using Scanner class
object then sort in (Ascending) Order by using Approach of (Iterative Insertion Sort Algorithm).
125 | P a g e
6)Create a function to sort Integer Array which should be taken as Input from user by using Scanner cla ss
object then sort in
7)Create a function to sort Integer Array which should be taken as Input from user by using Scanner class
object then sort in (Descending) Order by using Approach of (Iterative Insertion Sort Algorithm).
8)Create a function to sort Integer Array which should be taken as Input from user by using Scanner class
object then sort in (Descending) Order by using Approach of (Recursive Insertion Sort Algorithm).
9)Create a function to sort Integer Array which should be taken as Input from user by using Scanner class
object then sort in
10)Create a function to sort Integer Array which should be taken as Input from user by using Scanner
class object then sort in
11)Create a function to sort Integer Array which should be taken as Input from user by using Scanner
class object then sort in (Descending) Order by using Approach of (Iterative Bubble Sort Algorithm).
12)Create a function to sort Integer Array which should be taken as Input from user by using Scanner
class object then sort in (Descending) Order by using Approach of (Recursive Bubble Sort Algorithm).
126 | P a g e
Lab’s Evaluation Sheet
Students Registration No
Date Performed:
Group No:
Date of Submission
Marks /Grade
Sr. No. Categories Total Marks/Grade
Obtained
3 On Time Submission 5
4 Home Activity 10
Net Result 20
127 | P a g e
Experiment # 12
OBJECTIVE:
Sorting Algorithms including Merge Sort & Quick Sort Implementations.
128 | P a g e
129 | P a g e
130 | P a g e
131 | P a g e
132 | P a g e
133 | P a g e
134 | P a g e
135 | P a g e
136 | P a g e
137 | P a g e
138 | P a g e
139 | P a g e
140 | P a g e
141 | P a g e
142 | P a g e
Lab Tasks:
143 | P a g e
Lab’s Evaluation Sheet
Students Registration No
Date Performed:
Group No:
Date of Submission
Marks /Grade
Sr. No. Categories Total Marks/Grade
Obtained
Net Result 20
144 | P a g e
Experiment # 13
OBJECTIVE:
Binary Search Tree Introduction and Implementation with Exercises of Various
Functions and Traversal Algorithms.
BACKGROUND THEORY:
In computer science, a binary search tree (BST), also called an ordered or sorted binary tree, is a rooted
binary tree whose internal nodes each store a key greater than all the keys in the node's left subtree and less
than those in its right subtree. A binary tree is a type of data structure for storing data such as numbers in
an organized way. Binary search trees allow binary search for fast lookup, addition and removal of data
items . The order of nodes in a BST means that each comparison skips about half of the remaining tree, so
the whole lookup takes time proportional to the binary logarithm of the number of items stored in the tree.
This is much better than the linear time required to find items by key in an (unsorted) array
145 | P a g e
146 | P a g e
147 | P a g e
148 | P a g e
149 | P a g e
150 | P a g e
151 | P a g e
152 | P a g e
153 | P a g e
154 | P a g e
155 | P a g e
156 | P a g e
157 | P a g e
158 | P a g e
159 | P a g e
160 | P a g e
161 | P a g e
162 | P a g e
163 | P a g e
Lab Tasks:
1) Create a method by which we can INSERT INT value in BINARY SEARCH TREE.
2) Create methods by which we can FIND INT value in BST & Calculate Height Of BST.
3) Create methods to Traverse Tree in PRE Order Traversal, POST Order Traversal, IN Order
Traversal.
4) Create methods to return MAX & MIN value in BST.
5) Create methods to Validate BST & Find Equality of Two BSTs.
164 | P a g e
Lab’s Evaluation Sheet
Students Registration No
Date Performed:
Group No:
Date of Submission
Marks /Grade
Sr. No. Categories Total Marks/Grade
Obtained
Net Result 20
165 | P a g e
Experiment # 14
OBJECTIVE:
AVL Tree Introduction and Implementation with Exercises of Various Functions and
Rotations.
166 | P a g e
167 | P a g e
168 | P a g e
169 | P a g e
170 | P a g e
171 | P a g e
172 | P a g e
173 | P a g e
174 | P a g e
175 | P a g e
Lab Tasks:
176 | P a g e
Lab’s Evaluation Sheet
Students Registration No
Date Performed:
Group No:
Date of Submission
Marks /Grade
Sr. No. Categories Total Marks/Grade
Obtained
Net Result 20
177 | P a g e