Data Structure(2024-25)
Data Structure(2024-25)
New Horizon
Institute of Technology and Management, Thane
Affiliated to University of Mumbai
Lab Manual
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. Modern Tool Usage: Create, select, and apply appropriate techniques, resources, and
modern engineering and IT tools including prediction and modeling to complex engineering
activities with an understanding of the limitations.
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. Ethics: Apply ethical principles and commit to professional ethics and responsibilities and
norms of the engineering practice.
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. 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.
Cognitive Level
Course Outcome (Remember,
Hours
CO At the end of the course student will be able to: Understand, Apply,
Planned
Create, Analyze,
Evaluate)
Classify and Apply the concepts of Linear and Non-
Linear data structures in real life problem solving and Understand,
1 2
apply the operations like insertion, deletion, and Apply,Analyze
traversal operations on them.
Explore data structures such as Stacks, learn about their Understand,
2 operations, and use them to solve problems in a variety Apply,Analyze, 4
of domains. Evaluate
Understand,
Examine Queue data structures and use them to address Apply,Analyze, 5
3
real-world problems.
Evaluate
Apply the concept of Linked list to evaluate the Understand,
4 6
problems in a diverse applications Apply,Analyze
Understand,
Analyze and apply the concepts of Trees and their Apply,Analyze, 5
5
applications in real life problem solving. Evaluate
Demonstrate the ability to analyze, construct,
Apply,Analyze, 4
6 implement, and use data structures to solve
real-world problems and evaluate their effectiveness. Evaluate
Sr. No Title No of
Hours
2 CO 1
5 Implementation of Stack using Linked list CO 2
CO 4
2 CO 1
6 Implementation of Double Ended Queue using Linked List CO 3
CO 4
IEN: - Batch: -
Name of the Student: - Div.: -
Date of Performance: -
EXPERIMENT NO.: - 01
An Abstract Data Type (ADT) is a conceptual model that defines a set of operations and behaviors
for a data structure, without specifying how these operations are implemented or how data is
organized in memory. The definition of ADT only mentions what operations are to be performed but
not how these operations will be implemented. It does not specify how data will be organized in
memory and what algorithms will be used for implementing the operations. It is called “abstract”
because it provides an implementation-independent view.
The process of providing only the essentials and hiding the details is known as abstraction.
For example, we use primitive values like int, float, and char with the understanding that these data
types can operate and be performed on without any knowledge of their implementation details. ADTs
operate similarly by defining what operations are possible without detailing their implementation.
Definition Defines a class of objects and the A custom data type created by
operations that can be performed combining or extending existing
on them, along with their primitive types, specifying both
expected behavior (semantics), structure and operations.
but without specifying
implementation details.
Focus What operations are allowed and How data is organized in memory
how they behave, without and how operations are executed.
dictating how they are
implemented.
Implementa Does not specify how operations Specifies how to create and
tion Details are implemented or how data is organize data types to implement
structured. the structure.
Array is a container which can hold a fix number of items and these items should be of the
same type. Most of the data structures make use of arrays to implement their algorithms.
Following are the important terms to understand the concept of Array.
● Element − Each item stored in an array is called an element.
● Index − Each location of an element in an array has a numerical index, which is
used to identify the element.
Array Representation:(Storage structure)
Arrays can be declared in various ways in different languages. C language array declaration
is shown below:
Experiment Rubric:
Signature of
Evaluation Criteria Marks Instructor with Date
Lab Performance
Topic Knowledge
Task Conclusion
Attainment Level (Out of 3)
IEN: - Batch: -
Name of the Student: - Div.: -
Date of Performance: -
EXPERIMENT NO.: - 02
1 Stack as an ADT
A stack is a linear data structure that follows the Last In, First Out (LIFO) principle. This means that the most
recently added item is the first one to be removed.
An array can be used to implement a stack by maintaining an index (often called top) that tracks the
position of the top item in the stack. The array will store the elements of the stack, and the top index helps in
determining where the next item will be pushed or where the item will be popped from.
Primary Operations:
● Push: Add an item to the top of the stack.
● Pop: Remove the item from the top of the stack.
● Peek/Top: View the item at the top of the stack without removing it.
● IsEmpty: Check if the stack is empty.
● Display stack: Display the stack.
ALGORITHM :-
-1 Step 5 : Stop
Step 5 : Stack
[top]element Step 6 :
Stop
Experiment Rubric:
Signature of
Evaluation Criteria Marks Instructor with Date
Lab Performance
Topic Knowledge
Task Conclusion
Attainment Level (Out of 3)
IEN: - Batch: -
Name of the Student: - Div.: -
Date of Performance: -
EXPERIMENT NO.: - 03
1 Queue as an ADT
A Queue is a linear data structure that follows the First In, First Out(FILO) principle. This means that the most
recently added item is the last one to be removed.
Primary Operations:
Enqueue (Insertion): Adds an element at the rear position and increments rear.
Dequeue (Deletion): Removes an element from the front and increments front.
Peek: Retrieves the front element without removing it.
isEmpty: Checks if the queue is empty (front > rear).
isFull: Checks if the queue is full (rear == size - 1).
ALGORITHM :-
Algorithm to implement the enqueue(Insertion) operation of queue
Step 1: Start
Step 2: Check if the queue is full
If rear == size - 1, print "Queue is Full" and exit
Step 3: If the queue is empty (front == -1), set front = 0
Step 4: Increment rear by 1 (rear = rear + 1)
Step 5: Insert the new element at queue[rear]
Step 6: End
Experiment Rubric:
Signature of
Evaluation Criteria Marks Instructor with Date
Lab Performance
Topic Knowledge
Task Conclusion
Attainment Level (Out of 3)
IEN: - Batch: -
Name of the Student: - Div.: -
Date of Performance: -
Course Outcome: - Students will be able to implement linear data structures & be able to handle
EXPERIMENT NO.: - 04
Single linked list is the basic form of linked list.in this linked list every node is made up of two parts: data and
next Data part contain the actual elements while next part contains address of next node.the next part of last node
always contains null value.It is a one way traversing list,which means we can traverse only in forward directions
we cannot traverse in backward direction.Suppose we have three nodes, and the addresses of these three nodes
are 100, 200 and 300 respectively. The representation of three nodes as a linked list is shown in the below
figure:The first node contains the address of the next node, i.e., 200, the second node
contains the address of the last node, i.e., 300, and the third node contains the NULL value in its address part as
it does not point to any node. The pointer that holds the address of the
The initial node is known as a head pointer.
2. Searching
3. Inserting at end
4. Inserting at beginning
5. Inserting at middle
© New Horizon Institute of Technology and Management www.nhitm.ac.in 12 | Page
Data Structure Course Code:PCC2011 Lab Manual
6. Deleting First
7. Deleting Last
8. Deleting middle
Algorithm:
Step 1. Start
Step 3. Create a Head node with label = -1 and next = NULL using
Step 15. Traverse the list from Head node to node which points to null
Result:
Conclusion:
Experiment Rubric:
Signature of
Evaluation Criteria Marks
Instructor with Date
Lab Performance
Topic Knowledge
Task Conclusion
Attainment Level (Out of 3)
IEN: - Batch: -
Name of the Student: - Div.: -
Date of Performance: -
Course Outcome: - Students will be able to implement linear data structures & be able to handle
operations like insertion, deletion, searching and traversing on them.
EXPERIMENT NO.: - 05
To implement a stack using the singly linked list concept, all the singly linked list operations should be performed
based on Stack operations LIFO(last in first out) and with the help of that knowledge, we are going to implement
a stack using a singly linked list. So we need to follow a simple rule in the implementation of a stack which is
last in first out and all the operations can be performed with the help of a top variable. Let us learn how to perform
Pop, Push, Peek, and Display operations in the following article:
Step 1. Start
Step 2. Create a new node with the value to be inserted.
Step 3. If the Stack is empty, set the next of the new nodes to null.
Step 4. If the Stack is not empty, set the next of the new nodes to top.
Step 5. Finally, increment the top to point to the new node.
Step 6. Stop
Result:
Conclusion:
Experiment Rubric:
Signature of
Evaluation Criteria Marks
Instructor with Date
Lab Performance
Topic Knowledge
Task Conclusion
Attainment Level (Out of 3)
IEN: - Batch: -
Name of the Student: - Div.: -
Date of Performance: -
Course Outcome: - Students will be able to implement linear data structures & be able to handle
operations like insertion, deletion, searching and traversing on them.
EXPERIMENT NO.: - 06
A Double-Ended Queue (Deque) is a linear data structure that allows insertion and deletion of elements from
both ends, i.e., front and rear. There are two types of deques:
1. Input Restricted Deque: Allows insertion at only one end but deletion from both ends.
2. Output Restricted Deque: Allows deletion from only one end but insertion from both ends.
Using a linked list, we can implement a dynamic deque where elements can be added or removed efficiently
without memory wastage.
Algorithm
1. Insertion at Front:
Step 1. Start
Step 2. Create a new node.
Step 3. If the deque is empty, set the new node as both front and rear.
Step 4. Otherwise, insert the node at the front and update the pointers.
Step 5. Stop
2. Insertion at Rear:
Step 1. Create a new node.
Step 2. If the deque is empty, set the new node as both front and rear.
Step 3. Otherwise, insert the node at the rear and update the pointers.
Result:
Conclusion:
Experiment Rubric:
Signature of
Evaluation Criteria Marks
Instructor with Date
Lab Performance
Topic Knowledge
Task Conclusion
Attainment Level (Out of 3)
IEN: - Batch: -
Name of the Student: - Div.: -
Date of Performance: -
EXPERIMENT NO.: - 07
Algorithm
1. Insertion into BST:
Step 1. Start
Step 2. If the tree is empty, create a new node as the root.
Step 3. Otherwise, compare the value with the root:
a. If it is smaller, insert it in the left subtree.
b. If it is greater, insert it in the right subtree.
Step 4. Repeat until the correct position is found.
Step 5. Stop
© New Horizon Institute of Technology and Management www.nhitm.ac.in 19 | Page
Data Structure Course Code:PCC2011 Lab Manual
2. Inorder Traversal:
Step 1. Start
Step 2. Recursively traverse the left subtree.
Step 3. Print the value of the current node.
Step 4. Recursively traverse the right subtree.
Step 5. Stop
3. Preorder Traversal:
Step 1. Start
Step 2. Print the value of the current node.
Step 3. Recursively traverse the left subtree.
Step 4. Recursively traverse the right subtree.
Step 5. Stop
4. Postorder Traversal:
Step 1. Start
Step 2. Recursively traverse the left subtree.
Step 3. Recursively traverse the right subtree.
Step 4. Print the value of the current node.
Step 5. stop
Experiment Rubric:
Signature of
Evaluation Criteria Marks Instructor with Date
Lab Performance
Topic Knowledge
Task Conclusion
Attainment Level (Out of 3)
IEN: - Batch: -
Name of the Student: - Div.: -
Date of Performance: -
EXPERIMENT NO.: - 08
Operations :
1. Counting Leaf Nodes: A leaf node is a node that has no children (left and right pointers are NULL).
2. Finding the Smallest Element: The leftmost node in the BST contains the smallest element.
3. Finding the Largest Element: The rightmost node in the BST contains the largest element.
4. Calculating the Height of the BST: The height of a tree is the number of edges on the longest path
from the root to a leaf node.
Algorithm
1. Insertion into BST:
Step 1. Start
Step 2. If the tree is empty, create a new node as the root.
Step 3. Otherwise, compare the value with the root:
o If it is smaller, insert it in the left subtree.
o If it is greater, insert it in the right subtree.
Step 4. Repeat until the correct position is found.
Step 5. Stop
© New Horizon Institute of Technology and Management www.nhitm.ac.in 21 | Page
Data Structure Course Code:PCC2011 Lab Manual
Step 1. Start
Step 2. If the tree is empty, return 0.
Step 3. If the node has no left or right children, return 1.
Step 4. Recursively count leaf nodes in the left and right subtrees.
Step 5. Stop
Step 1. Start
Step 2. Traverse the left subtree until the leftmost node is found.
Step 3. Return the data of the leftmost node.
Step 4. Stop
Step 1. Start
Step 2. Traverse the right subtree until the rightmost node is found.
Step 3. Return the data of the rightmost node.
Step 4. Stop
Step 1. Start
Step 2. If the tree is empty, return -1.
Step 3. Recursively calculate the height of the left and right subtrees.
Step 4. Return the maximum of both heights plus one.
Step 5. Stop
Experiment Rubric:
Signature of
Evaluation Criteria Marks Instructor with Date
Lab Performance
Topic Knowledge
Task Conclusion
Attainment Level (Out of 3)
IEN: - Batch: -
Name of the Student: - Div.: -
Date of Performance: -
EXPERIMENT NO.: - 09
An infix expression in a High Level Language program is converted into its postfix compilation time,
since the evaluation of a postfix expression is much simpler than direct evaluation of an infix
expression.
The postfix expression is evaluated using Stack. Following is the method for evaluation postfix
expressions:
2) Scan the given expression and do the following for every scanned element.
b) If the element is an operator, pop operands for the operator from stack. Evaluate the operator and
push the result back to the stack.
3) When the expression is ended, the number in the stack is the final
answer Example:
*+ 432 Pop 4 & pop 3 from stack and do 3 *4 , push 12 onto stack
Experiment Rubric:
Signature of
Evaluation Criteria Marks Instructor with Date
Lab Performance
Topic Knowledge
Task Conclusion
Attainment Level (Out of 3)
IEN: - Batch: -
Name of the Student: - Div.: -
Date of Performance: -
EXPERIMENT NO.: - 10
A stack is a linear data structure that follows the Last In, First Out (LIFO) principle. This means that the
most recently added item is the first one to be removed.
ALGORITHM :-
Step 1: Start.
Step 2: Create an empty stack.
Step 3: Traverse the given list and push each element onto the stack using the ‘push’ function.
Step 4: Pop elements from the stack using the ‘pop’ function and display them.
Step 5: Stop.
Experiment Rubric:
Signature of
Evaluation Criteria Marks Instructor with Date
Lab Performance
Topic Knowledge
Task Conclusion
Attainment Level (Out of 3)