0% found this document useful (0 votes)
1 views

Data Structure(2024-25)

This document is a lab manual for the Data Structure course (PCC2011) at New Horizon Institute of Technology and Management for the academic year 2024-2025. It outlines the program outcomes, course outcomes, and various experiments related to data structures, including arrays, stacks, queues, and linked lists, along with their implementation details and algorithms. The manual emphasizes the application of theoretical concepts in practical scenarios to solve real-world problems using different data structures.

Uploaded by

andhaleomkar1
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views

Data Structure(2024-25)

This document is a lab manual for the Data Structure course (PCC2011) at New Horizon Institute of Technology and Management for the academic year 2024-2025. It outlines the program outcomes, course outcomes, and various experiments related to data structures, including arrays, stacks, queues, and linked lists, along with their implementation details and algorithms. The manual emphasizes the application of theoretical concepts in practical scenarios to solve real-world problems using different data structures.

Uploaded by

andhaleomkar1
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 26

Data Structure Course Code:PCC2011 Lab Manual

New Horizon
Institute of Technology and Management, Thane
Affiliated to University of Mumbai

Program: Humanities and Applied Science

Course: Data Structure

Lab Manual

Course Code: PCC2011


Academic Year: 2024-2025

© New Horizon Institute of Technology and Management www.nhitm.ac.in 1 | Page


Data Structure Course Code:PCC2011 Lab Manual

Program Outcomes (POs)


1. Engineering knowledge: Apply the knowledge of mathematics, science, engineering
fundamentals, and an engineering specialization to the solution of complex engineering problems.

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.

3. 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.

4. 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.

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.

7. 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.

8. Ethics: Apply ethical principles and commit to professional ethics and responsibilities and
norms of the engineering practice.

9. Individual and Team work: Function effectively as an individual, and as a member or


leader in diverse teams, and in multidisciplinary settings.

10. Communication: Communicate effectively on complex engineering activities with the


engineering community and with society at large, such as, being able to comprehend and write
effective reports and design documentation, make effective presentations, and give and receive
clear instructions.

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.

© New Horizon Institute of Technology and Management www.nhitm.ac.in 2 | Page


Data Structure Course Code:PCC2011 Lab Manual

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

Total Hours Planned 26

© New Horizon Institute of Technology and Management www.nhitm.ac.in 3 | Page


Data Structure Course Code:PCC2011 Lab Manual

Sr. No Title No of
Hours

1 Implementation of Insertion and deletion in a specific position in an 2 CO 1


Array using Function CO 2

2 Array Implementation of Stack (1. Push 2. Pop 3. Display stack 4. 2 CO 1


Exit) CO 2

3 Array Implementation of Linear Queue (1. Insert an element 2. 2 CO 1


Delete an element 3. Display queue 4. Exit) CO 3

4 Implement Singly Linked List (1. Insert a node 2. Delete a node 3. 2 CO 1


Display all nodes 4. Exit) CO 2
CO 4

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

7 Implementation of Binary Search Tree and its traversal methods 2 CO 1


CO 5

8 Program to count Number of leaf nodes, find the biggest and 2 CO 1


smallest and height of the tree CO 5

9 Program to Evaluate Postfix Expression using Stack ADT 2 CO 1


CO 2

10 Implementation of Reversing a List using Stack. 2 CO 1


CO 2

© New Horizon Institute of Technology and Management www.nhitm.ac.in 4 | Page


Data Structure Course Code:PCC2011 Lab Manual

IEN: - Batch: -
Name of the Student: - Div.: -
Date of Performance: -

EXPERIMENT NO.: - 01

Title: Array Operations


Aim: - Implementation of Insertion and deletion in a specific position in an Array
using Function.
System Software Requirements: - Linux Text Editor, Terminal

Theory/ Working Principle:

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.

Difference Between ADTs and UDTs


Aspect Abstract Data Types (ADTs) User-Defined Data Types
(UDTs)

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.

© New Horizon Institute of Technology and Management www.nhitm.ac.in 5 | Page


Data Structure Course Code:PCC2011 Lab Manual

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.

Purpose Provides an abstract model to Allows programmers to create


define data structures in a concrete implementations of data
conceptual way. structures using primitive types.

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.

Usage Used to design and conceptualize Used to implement data structures


data structures. that realize the abstract concepts
defined by ADTs.

Example List ADT, Stack ADT, Queue Structures, classes, enumerations,


ADT. records.

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:

© New Horizon Institute of Technology and Management www.nhitm.ac.in 6 | Page


Data Structure Course Code:PCC2011 Lab Manual
● Index starts with 0.
● Array length is 10 which means it can store 10 elements.
● Each element can be accessed via its index. For example, we can fetch an element at index 6 as 9.
Basic Operations
Following are the basic operations supported by an array.
● Traverse − print all the array elements one by one.
● Insertion − Adds an element at the given index.
● Deletion − Deletes an element at the given index.
● Search − Searches an element using the given index or by the value.
● Update − Updates an element at the given index.

Program code and output is attached herewith.

Experiment Rubric:
Signature of
Evaluation Criteria Marks Instructor with Date
Lab Performance
Topic Knowledge
Task Conclusion
Attainment Level (Out of 3)

© New Horizon Institute of Technology and Management www.nhitm.ac.in 7 | Page


Data Structure Course Code:PCC2011 Lab Manual

IEN: - Batch: -
Name of the Student: - Div.: -
Date of Performance: -

EXPERIMENT NO.: - 02

Title: Stack Operations


Aim: - Array Implementation of Stack
System Software Requirements: - Linux Text Editor, Terminal

Theory/ Working Principle:

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.

2. Stack Implementation Using Array

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 :-

Algorithm to implement the pop operation of stack


Step 1: Start

Step 2: If top =1 goto Step 3 else goto step 4

Step 3 : Display the message ,”Stack Empty “ and Exit

© New Horizon Institute of Technology and Management www.nhitm.ac.in 8 | Page


Data Structure Course Code:PCC2011 Lab Manual
Step 4 : Return stack[top] and top = top

-1 Step 5 : Stop

Algorithm to implement the push operation of stack


Step 1 : Start

Step 2 : If top = max -1 goto step 3 else goto

step 4 Step 3 : Display message “Stack Full

” and exit Step 4 : top = top +1

Step 5 : Stack

[top]element Step 6 :

Stop

Program code and output is attached herewith.

Experiment Rubric:

Signature of
Evaluation Criteria Marks Instructor with Date
Lab Performance
Topic Knowledge
Task Conclusion
Attainment Level (Out of 3)

© New Horizon Institute of Technology and Management www.nhitm.ac.in 9 | Page


Data Structure Course Code:PCC2011 Lab Manual

IEN: - Batch: -
Name of the Student: - Div.: -
Date of Performance: -

EXPERIMENT NO.: - 03

Title: Queue Operations


Aim: - Array Implementation of Queue
System Software Requirements: - Linux Text Editor, Terminal

Theory/ Working Principle:

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.

3. Queue Implementation Using Array


A Queue is a linear data structure that follows the FIFO (First In, First Out) principle. It can be efficiently
implemented using an array. Two pointers, rear and front, are used to track the positions of the last and first items
in the queue. The array stores the elements of the queue, with the rear index indicating where the next item will be
enqueued (inserted) and the front index indicating where the item will be dequeued (deleted).

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

© New Horizon Institute of Technology and Management www.nhitm.ac.in 10 | Page


Data Structure Course Code:PCC2011 Lab Manual
Algorithm to implement the dequeue(Deletion) operation of stack
Step 1: Start
Step 2: Check if the queue is empty
 If front == -1 or front > rear, print "Queue is Empty" and stop.
Step 3: Remove the element from queue[front].
Step 4: Move front forward by 1 (front = front + 1).
Step 5: If the queue becomes empty after deletion (front > rear), reset front = -1 and rear = -1.
Step 6: End.Program code and output is attached herewith.

Experiment Rubric:

Signature of
Evaluation Criteria Marks Instructor with Date
Lab Performance
Topic Knowledge
Task Conclusion
Attainment Level (Out of 3)

© New Horizon Institute of Technology and Management www.nhitm.ac.in 11 | Page


Data Structure Course Code:PCC2011 Lab Manual

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.: - 04

Title: Singly Linked list

Aim: Implement Singly Linked list ADT

System Software Requirements: Visual Studio/Turbo c++


Theory/ Working Principle:

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.

Operations On Single-linked List:


1. Traversing

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 2. Define single linked list node as self referential structure

Step 3. Create a Head node with label = -1 and next = NULL using

Step 4. Display menu on list operation

Step 5. Accept user choice

Step 6. If choice = 1 then

Step 7. Locate node after which insertion is to be done

Step 8. Create a new node and get data part

Step 9. Insert the new node at appropriate position by manipulating address

Step 10. Else if choice = 2

Step 11. Get node's data to be deleted.

Step 12. Locate the node and delink the node

Step 13. Rearrange the links

© New Horizon Institute of Technology and Management www.nhitm.ac.in 13 | Page


Data Structure Course Code:PCC2011 Lab Manual
Step 14. Else

Step 15. Traverse the list from Head node to node which points to null

Step 16. Stop

Result:
Conclusion:

Experiment Rubric:

Signature of
Evaluation Criteria Marks
Instructor with Date
Lab Performance
Topic Knowledge
Task Conclusion
Attainment Level (Out of 3)

© New Horizon Institute of Technology and Management www.nhitm.ac.in 14 | Page


Data Structure Course Code:PCC2011 Lab Manual

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

Title: Linked Stack.

Aim: - Implement Stack ADT using Linked List.

System Software Requirements: - Visual Studio/Turbo c++

Theory/ Working Principle:

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:

© New Horizon Institute of Technology and Management www.nhitm.ac.in 15 | Page


Data Structure Course Code:PCC2011 Lab Manual
Algorithm

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)

© New Horizon Institute of Technology and Management www.nhitm.ac.in 16 | Page


Data Structure Course Code:PCC2011 Lab Manual

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

Title: Linked Queue(Double Ended Queue).

Aim: - Implement Double Ended Queue using Linked List.

System Software Requirements: - Visual Studio/Turbo c++

Theory/ Working Principle:

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.

© New Horizon Institute of Technology and Management www.nhitm.ac.in 17 | Page


Data Structure Course Code:PCC2011 Lab Manual

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.

3. Deletion from Front:


Step 1. If the deque is empty, print an underflow message.
Step 2. Remove the front node and update the pointers.
Step 3. If the deque becomes empty, set front and rear to NULL.
4. Deletion from Rear:
Step 1. If the deque is empty, print an underflow message.
Step 2. Remove the rear node and update the pointers.
Step 3. If the deque becomes empty, set front and rear to NULL.
5. Display Deque:
Step 1. Traverse from front to rear and print each node’s value.

Result:

Conclusion:

Experiment Rubric:

Signature of
Evaluation Criteria Marks
Instructor with Date
Lab Performance
Topic Knowledge
Task Conclusion
Attainment Level (Out of 3)

© New Horizon Institute of Technology and Management www.nhitm.ac.in 18 | Page


Data Structure Course Code:PCC2011 Lab Manual

IEN: - Batch: -
Name of the Student: - Div.: -
Date of Performance: -

EXPERIMENT NO.: - 07

Title: Binary Search Tree


Aim: - Implementation of Binary Search Tree and it’s traversal methods.
System Software Requirements: - Linux Text Editor, Terminal

Theory/ Working Principle:


A Binary Search Tree (BST) is a data structure where each node has at most two children, referred to as
the left child and the right child. For any given node, all values in the left subtree are less than the node's
value, and all values in the right subtree are greater.

Properties of Binary Search Tree


Following are some main properties of the binary search tree in C:
● All nodes of the left subtree are less than the root node and nodes of the right subtree are greater than the
root node.
● The In-order traversal of binary search trees gives the values in ascending order.
All the subtrees of BST hold the same properties.
.

Tree Traversal Methods:

1. Inorder Traversal (Left, Root, Right)


2. Preorder Traversal (Root, Left, Right)
3. Postorder Traversal (Left, Right, Root)

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)

© New Horizon Institute of Technology and Management www.nhitm.ac.in 20 | Page


Data Structure Course Code:PCC2011 Lab Manual

IEN: - Batch: -
Name of the Student: - Div.: -
Date of Performance: -

EXPERIMENT NO.: - 08

Title: Binary Search Tree


Aim: - To implement a Binary Search Tree (BST) and perform some operations like Count the number of
leaf nodes,Find the smallest and largest elements in the BST and Determine the height of the BST.

System Software Requirements: - Linux Text Editor, Terminal

Theory/ Working Principle:


A Binary Search Tree (BST) is a data structure where each node has at most two children, referred to as
the left child and the right child. For any given node, all values in the left subtree are less than the node's
value, and all values in the right subtree are greater.

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

2. Counting Leaf Nodes:

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

3. Finding the Smallest Element:

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

4. Finding the Largest Element:

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

5. Calculating the Height of the BST:

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)

© New Horizon Institute of Technology and Management www.nhitm.ac.in 22 | Page


Data Structure Course Code:PCC2011 Lab Manual

IEN: - Batch: -
Name of the Student: - Div.: -
Date of Performance: -

EXPERIMENT NO.: - 09

Title: Evaluate Postfix expression using stack ADT.

Aim: - Program to Evaluate Postfix Expression using Stack ADT.


System Software Requirements: - Linux Text Editor, Terminal

Theory/ Working Principle:

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:

1) Create a stack to store operands.

2) Scan the given expression and do the following for every scanned element.

a) If the element is a number, push it into the stack.

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

© New Horizon Institute of Technology and Management www.nhitm.ac.in 23 | Page


Data Structure Course Code:PCC2011 Lab Manual

answer Example:

Input Stack Postfix evaluation

234*+ empty Push 2 onto stack

34*+ 2 Push 3 onto stack

4*+ 32 Push 4 onto stack

*+ 432 Pop 4 & pop 3 from stack and do 3 *4 , push 12 onto stack

+ 12 2 Pop 12 & Pop 2 from stack do 2 + 12, push 14 onto stack

14 Pop 14, the answer

Experiment Rubric:
Signature of
Evaluation Criteria Marks Instructor with Date
Lab Performance
Topic Knowledge
Task Conclusion
Attainment Level (Out of 3)

© New Horizon Institute of Technology and Management www.nhitm.ac.in 24 | Page


Data Structure Course Code:PCC2011 Lab Manual

IEN: - Batch: -
Name of the Student: - Div.: -
Date of Performance: -

EXPERIMENT NO.: - 10

Title: Reversing a List(Stack)


Aim: - Implement the concept of reversing a list using a stack in a programming language

System Software Requirements: - Linux Text Editor, Terminal

Theory/ Working Principle:

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.

Implementation Using Array


A stack is a linear data structure that follows the Last In, First Out (LIFO) principle. Reversing a list using
a stack involves pushing each element of the list onto the stack and then popping them out, which results in
a reversed order.

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.

© New Horizon Institute of Technology and Management www.nhitm.ac.in 25 | Page


Data Structure Course Code:PCC2011 Lab Manual

Experiment Rubric:
Signature of
Evaluation Criteria Marks Instructor with Date
Lab Performance
Topic Knowledge
Task Conclusion
Attainment Level (Out of 3)

© New Horizon Institute of Technology and Management www.nhitm.ac.in 26 | Page

You might also like