Understanding Stack Data Structure
Understanding Stack Data Structure
SEM III
Module 2
Prof Jeenal
Stacks
●Stack is a simple data structure that allows adding and removing elements in a
particular order.
●Every time an element is added, it goes on the top of the stack and the only
element that can be removed is the element that is at the top of the stack, just like
a pile of objects.
Prof Jeenal
Stacks
Prof Jeenal
Stacks
Prof Jeenal
Stacks
Insertion: push()
●push() is an operation that inserts elements into the stack. The following is
an algorithm that describes the push() operation in a simpler way.
Algorithm
1 − Checks if the stack is full.
2 − If the stack is full, produces an error and exit.
3 − If the stack is not full, increments top to point next empty space.
4 − Adds data element to the stack location, where top is pointing.
5 − Returns success.
Prof Jeenal
Stacks
●Deletion: pop()
●pop() is a data manipulation operation which removes elements from the stack. The
following pseudo code describes the pop() operation in a simpler way.
●Algorithm
1 − Checks if the stack is empty.
2 − If the stack is empty, produces an error and exit.
3 − If the stack is not empty, accesses the data element at which top is pointing.
4 − Decreases the value of top by 1.
5 − Returns success.
Prof Jeenal
Stacks
peek()
●The peek() is an operation retrieves the topmost element within the
stack, without deleting it. This operation is used to check the status of
the stack with the help of the top pointer.
Algorithm
1. START
2. return the element at the top of the stack
3. END
Prof Jeenal
Stacks
isFull()
●isFull() operation checks whether the stack is full. This operation is
used to check the status of the stack with the help of top pointer.
Algorithm
1. START
2. If the size of the stack is equal to the top position of the stack, the
stack is full. Return 1.
3. Otherwise, return 0.
4. END
Prof Jeenal
Stacks
isEmpty()
●The isEmpty() operation verifies whether the stack is empty. This
operation is used to check the status of the stack with the help of top
pointer.
Algorithm
1. START
2. If the top value is -1, the stack is empty. Return 1.
3. Otherwise, return 0.
4. END Prof Jeenal
Stacks
push(): When we embed a component in a stack then the activity is known as
a push. On the off chance that the stack is full, at that point the flood condition
happens.
pop(): When we erase a component from the stack, the activity is known as a
pop. In the event that the stack is unfilled implies that no component exists in
the stack, this state is known as an undercurrent state.
isEmpty(): It decides if the stack is unfilled or not.
isFull(): It decides if the stack is full or not.'
peek(): It restores the component at the given position.
count(): It restores the all out number of components accessible in a stack.
change(): It changes the component at the given position.
display(): It prints all the components accessible in the stack.
Prof Jeenal
Array implementation of Stack
#include <stdio.h>
#define MAX 5 // maximum size of stack
int stack[MAX];
int top = -1;
// Function to push an element
void push(int value) {
if(top == MAX - 1) {
printf("Stack Overflow! Cannot push %d\n", value);
} else {
top++;
stack[top] = value;
printf("%d pushed into stack.\n", value);
}
}
// Function to pop an element
void pop() {
if(top == -1) {
printf("Stack Underflow! Cannot pop.\n");
} else {
printf("%d popped from stack.\n", stack[top]);
top--;
}
} Prof Jeenal
Array implementation of Stack
// Function to display the stack
void display() {
int i;
if(top == -1) {
printf("Stack is empty.\n");
} else {
printf("Stack elements are:\n");
for(i = top; i >= 0; i--) {
printf("%d\n", stack[i]);
}
}
}
int main() {
int choice, value;
while(1) {
printf("\n*** Stack Menu ***\n");
printf("1. Push\n2. Pop\n3. Display\n4. Exit\n");
printf("Enter your choice: ");
scanf("%d", &choice);
Prof Jeenal
Array implementation of Stack
switch(choice) {
case 1:
printf("Enter value to push: ");
scanf("%d", &value);
push(value);
break;
case 2:
pop();
break;
case 3:
display();
break;
case 4:
printf("Exiting program.\n");
return 0;
default:
printf("Invalid choice! Try again.\n");
}
}
}
Prof Jeenal
Applications of Stack-Well form-ness of Parenthesis
• Given a string s representing an expression containing various types of
brackets: {}, (), and [], the task is to determine whether the brackets in the
expression are balanced or not. A balanced expression is one where every
opening bracket has a corresponding closing bracket in the correct order.
Example:
Input: s = "[{()}]"
Output: true
Explanation: All the brackets are well-formed.
Input: s = "[()()]{}"
Output: true
Explanation: All the brackets are well-formed.
Input: s = "([]"
Output: false
Explanation: The expression is not balanced as there is a missing ')' at the end.
Input: s = "([{]})"
Output: false
Explanation: The expression is not balanced because there is a closing ']' before
the closing '}'.
Prof Jeenal
Applications of Stack-Well form-ness of
Parenthesis
● The idea is to put all the opening brackets in the stack.
Whenever you hit a closing bracket, search if the top of the stack
is the opening bracket of the same nature. If this holds then pop
the stack and continue the iteration. In the end if the stack is
empty, it means all brackets are balanced or well-formed.
Otherwise, they are not balanced.
Prof Jeenal
Applications of Stack-Well form-ness of
Parenthesis
● Step-by-step approach:
● Declare a character stack (say temp).
● Now traverse the string s.
○ If the current character is an opening bracket ( '(' or '{' or '[' ) then push it to
stack.
○ If the current character is a closing bracket ( ')' or '}' or ']' ) and the closing
bracket matches with the opening bracket at the top of stack, then pop the
opening bracket. Else s is not balanced.
● After complete traversal, if some starting brackets are left in the stack then the
expression is not balanced, else balanced.
Prof Jeenal
Applications of Stack-Well form-ness of
Parenthesis
Prof Jeenal
Applications of Stack-Well form-ness of
Parenthesis
Prof Jeenal
Applications of Stack-Well form-ness of
Parenthesis
Prof Jeenal
Applications of Stack-Well form-ness of
Parenthesis
Prof Jeenal
Applications of Stack-Well form-ness of
Parenthesis
Prof Jeenal
Applications of Stack-Well form-ness of
Parenthesis
Prof Jeenal
Applications of Stack-Well form-ness of
Parenthesis
Prof Jeenal
Convert Infix expression to Postfix expression
Prof Jeenal
Convert Infix expression to Postfix expression
Prof Jeenal
Convert Infix expression to Postfix expression
Prof Jeenal
Convert Infix expression to Postfix expression
Below are the steps to implement the above idea:
[Link] the infix expression from left to right.
[Link] the scanned character is an operand, put it in the postfix
expression.
[Link], do the following
●If the precedence and associativity of the scanned operator are
greater than the precedence and associativity of the operator in the
stack [or the stack is empty or the stack contains a ‘(‘ ], then push it
in the stack. [‘^‘ operator is right associative and other operators like
‘+‘,’–‘,’*‘ and ‘/‘ are left-associative].
Prof Jeenal
Convert Infix expression to Postfix expression
●Check especially for a condition when the operator at the top of the
stack and the scanned operator both are ‘^‘. In this condition, the
precedence of the scanned operator is higher due to its right
associativity. So it will be pushed into the operator stack.
● In all the other cases when the top of the operator stack is the same
as the scanned operator, then pop the operator from the stack
because of left associativity due to which the scanned operator
has less precedence.
Prof Jeenal
Convert Infix expression to Postfix expression
●Else, Pop all the operators from the stack which are greater than or equal
to in precedence than that of the scanned operator. After doing that Push
the scanned operator to the stack. (If you encounter parenthesis while
popping then stop there and push the scanned operator in the stack.)
[Link] the scanned character is a ‘(‘, push it to the stack.
[Link] the scanned character is a ‘)’, pop the stack and output it until a ‘(‘ is
encountered, and discard both the parenthesis.
[Link] steps 2-5 until the infix expression is scanned.
[Link] the scanning is over, Pop the stack and add the operators in the
postfix expression until it is not empty.
[Link], print the postfix expression.
Prof Jeenal
Convert Infix expression to Postfix expression
● Print operands as they arrive
● If stack is empty or contains a left parenthesis on top, push the incoming operator
onto the stack
● If incoming symbol is '(', push it onto stack
● If incoming symbol is ')', pop the stack & print the operators until left parenthesis is
found.
● If incoming symbol has higher precedence than the top of the stack, push it on the
stack.
● If incoming symbol has lower precedence than the top of the stack, pop & print the
top. Then test the incoming operator against the new top of the stack.
● If incoming operator has equal precedence with the top of the stack, use
associativity rule.
● At the end of the expression, pop & print all operators of stack.
● Associativity Note:
● If associativity is L to R (Left to Right), then pop & print the top of the stack &
then push the incoming operator.
● If associativity is R to L (Right to Left), then push the incoming operator.
Convert Infix expression to Postfix expression
Consider the infix expression exp = “a+b*c+d” and the infix expression is
scanned using the iterator i, which is initialized as i = 0.
●1st Step: Here i = 0 and exp[i] = ‘a’ i.e., an operand. So add this in the postfix
expression. Therefore, postfix = “a”.
Prof Jeenal
Convert Infix expression to Postfix expression
●2nd Step: Here i = 1 and exp[i] = ‘+’ i.e., an operator. Push this into the stack.
postfix = “a” and stack = {+}.
Prof Jeenal
Convert Infix expression to Postfix expression
●3rd Step: Now i = 2 and exp[i] = ‘b’ i.e., an operand. So add this in the postfix
expression. postfix = “ab” and stack = {+}.
Prof Jeenal
Convert Infix expression to Postfix expression
●4th Step: Now i = 3 and exp[i] = ‘*’ i.e., an operator. Push this into the stack.
postfix = “ab” and stack = {+, *}.
Prof Jeenal
Convert Infix expression to Postfix expression
●5th Step: Now i = 4 and exp[i] = ‘c’ i.e., an operand. Add this in the postfix
expression. postfix = “abc” and stack = {+, *}.
Prof Jeenal
Convert Infix expression to Postfix expression
●6th Step: Now i = 5 and exp[i] = ‘+’ i.e., an operator. The topmost element of
the stack has higher precedence. So pop until the stack becomes empty or the top
element has less precedence. ‘*’ is popped and added in postfix. So postfix =
“abc*” and stack = {+}.
Prof Jeenal
Convert Infix expression to Postfix expression
●Now top element is ‘+‘ that also doesn’t have less precedence. Pop it. postfix = “abc*+”.
Prof Jeenal
Convert Infix expression to Postfix expression
●Now stack is empty. So push ‘ + ’ in the stack. stack = {+}.
Prof Jeenal
Convert Infix expression to Postfix expression
●7th Step: Now i = 6 and exp[i] = ‘d’ i.e., an operand. Add this in the postfix
expression. postfix = “abc*+d”.
Prof Jeenal
Convert Infix expression to Postfix expression
●Final Step: Now no element is left. So empty the stack and add it in the postfix
expression. postfix = “abc*+d+”.
Prof Jeenal
Operator precedence rule
Prof Jeenal
Infix to Post fix
Infix expression: K + L - M*N + (O^P) * W/U/V * T + Q
Prof Jeenal
Infix to Post fix
Infix expression: K + L - M*N + (O^P) * W/U/V * T + Q
Prof Jeenal
Infix to Post fix
Infix expression: K + L - M*N + (O^P) * W/U/V * T + Q
Prof Jeenal
Infix to Post fix
Infix expression: K + L - M*N + (O^P) * W/U/V * T + Q
Prof Jeenal
Infix to Post fix
Infix expression: K + L - M*N + (O^P) * W/U/V * T + Q
Prof Jeenal
Evaluation of Postfix Expression
Prof Jeenal
Evaluation of Postfix Expression
Prof Jeenal
Evaluation of Postfix Expression
Follow the steps mentioned below to evaluate postfix expression using stack:
● Create a stack to store operands (or values).
● Scan the given expression from left to right and do the following for
every scanned element.
● If the element is a number, push it into the stack.
● If the element is an operator, pop operands for the operator from the
stack. Evaluate the operator and push the result back to the stack.
● When the expression is ended, the number in the stack is the final answer.
Prof Jeenal
Evaluation of Postfix Expression
Prof Jeenal
Evaluation of Postfix Expression
Prof Jeenal
Evaluation of Postfix Expression
Prof Jeenal
Evaluation of Postfix Expression
● Scan *, it’s an operator. Pop two operands from stack, apply the * operator
on operands. We get 3*1 which results in 3. We push the result 3 to stack.
The stack now becomes ‘2 3’.
Prof Jeenal
Evaluation of Postfix Expression
● Scan +, it’s an operator. Pop two operands from stack, apply the + operator
on operands. We get 3 + 2 which results in 5. We push the result 5 to stack.
The stack now becomes ‘5’.
Prof Jeenal
Evaluation of Postfix Expression
● Scan 9, it’s a number. So we push it to the stack. The stack now becomes
‘5 9’.
Prof Jeenal
Evaluation of Postfix Expression
● Scan -, it’s an operator, pop two operands from stack, apply the – operator on
operands, we get 5 – 9 which results in -4. We push the result -4 to the stack.
The stack now becomes ‘-4’.
Prof Jeenal
Evaluation of Postfix Expression
● There are no more elements to scan, we return the top element from the stack
(which is the only element left in a stack).
Prof Jeenal
Recursion
● Recursion: The function calling itself is called recursion.
Prof Jeenal
Recursion
#include <stdio.h>
using namespace std;
int fact(int n)
{
if (n == 1)
return 1;
return fact(n - 1);
}
int main()
Prof Jeenal
{
Recursion
● For the above program. Firstly, the activation record for
main stack is generated and stored in the stack.
Prof Jeenal
Recursion
● In the above program, there is a recursive function fact
that has n as the local parameter. In the above example
program, n=2 is passed in the recursive function call.
● First Step: First, the function is invoked for n =2 and its
activation record are created in the recursive stack.
Prof Jeenal
Recursion
● 2nd Step: Then according to the recursive function, it is
invoked for n=1 and its activation record is created in the
recursive stack.
Prof Jeenal
Recursion
● 3rd Step: After the execution of the function for value n=1
as it is a base condition, its execution gets completed and
its activation record gets deleted.
Prof Jeenal
Recursion
● 4th step: Similarly, the function for value n=2(its previous
function) gets executed and its activation record gets
deleted. It comes out from the recursive function to the
main function.
Prof Jeenal
Recursion
● So, in the above example for recursive function fact and
value, n=2 recursive stack size excluding the main
function is 2. Hence, for value n recursive stack size is n.
Prof Jeenal
Queues
● Queue is an abstract data structure, somewhat similar to Stacks.
Unlike stacks, a queue is open at both its ends.
● One end is always used to insert data (enqueue) and the other is
used to remove data (dequeue).
● Queue follows First-In-First-Out methodology, i.e., the data
item stored first will be accessed first.
Prof Jeenal
Queues
● A Queue is a linear structure which follows a particular order in
which the operations are performed. The order is First In First
Out (FIFO).
● A good example of a queue is any queue of consumers for a
resource where the consumer that came first is served first.
● The difference between stacks and queues is in removing. In a
stack we remove the item the most recently added; in a queue,
we remove the item the least recently added.
Prof Jeenal
Queues
Prof Jeenal
OPERATIONS ON THE QUEUE
Prof Jeenal
Enqueue Operation
● Queues maintain two data pointers, front and rear. Therefore, its
operations are comparatively difficult to implement than that of stacks.
● The following steps should be taken to enqueue (insert) data into a queue
Step 1 − Check if the queue is full.
Step 2 − If the queue is full, produce overflow error and exit.
Step 3 − If the queue is not full, increment rear pointer to point the next
empty space.
Step 4 − Add data element to the queue location, where the rear is
pointing.
Step 5 − return success.
Prof Jeenal
Dequeue Operation
Prof Jeenal
Array implementation of Queue
● Like Stacks, Queues can also be represented in memory in two ways. Using
the contiguous memory like an array Using the non-contiguous memory
like a linked list Using the Contiguous Memory like an Array
● In this representation the Queue is implemented using the array. Variables
used in this case are
● QUEUE- the name of the array storing queue elements.
● FRONT- the index where the first element is stored in the array representing
the queue.
● REAR- the index where the last element is stored in array representing the
queue.
● MAX- defining that how many elements (maximum count) can be stored in
the array representing the queue.
Prof Jeenal
Array implementation of Queue
Prof Jeenal
Array implementation of Queue
● We can easily represent queue by using linear arrays. There are two
variables i.e. front and rear, that are implemented in the case of every
queue.
● Front and rear variables point to the position from where insertions and
deletions are performed in a queue.
● Initially, the value of front and rear is -1 which represents an empty
queue.
● Array representation of a queue containing 5 elements along with the
respective values of front and rear, is shown in the following figure.
Prof Jeenal
Array implementation of Queue
Array implementation of Queue
● The above figure shows the queue of characters forming the English
word "HELLO". Since, No deletion is performed in the queue till
now, therefore the value of front remains 0 .
● However, the value of rear increases by one every time an insertion is
performed in the queue.
● After inserting an element into the queue shown in the above figure,
the queue will look something like following. The value of rear will
become 5 while the value of front remains same.
Prof Jeenal
Queue
Prof Jeenal
Queue
After deleting an element, the value of front will increase from 0 to 1.
however, the queue will look something like following.
Prof Jeenal
Queue
#include <stdio.h>
#define SIZE 5 // Size of the queue
int queue[SIZE];
int front = -1, rear = -1;
return 0;
}
Prof Jeenal
Queue
o/p
Inserted 10
Inserted 20
Inserted 30
Queue elements are: 10 20 30
Deleted 10
Queue elements are: 20 30
Deleted 20
Deleted 30
Queue is empty
Types of queue
CIRCULAR QUEUE
A circular queue is the extended version of a regular queue where the last
element is connected to the first element. Thus forming a circle like structure.
Prof Jeenal
Circular queue
● The circular queue solves the major limitation of the normal queue. In
a normal queue, after a bit of insertion and deletion, there will be non
usable empty space.
● Here, indexes 0 and 1 can only be used after resetting the queue
(deletion of all elements). This reduces the actual size of the queue
Prof Jeenal
Circular queue
Prof Jeenal
Procedure on Circular Queue
Prof Jeenal
Enqueue operation
Prof Jeenal
Enqueue operation
Scenarios for inserting an element:
There are two scenarios in which queue is not full:
● If rear != max - 1, then rear will be incremented to mod(maxsize) and the
new value will be inserted at the rear end of the queue.
● If front != 0 and rear = max - 1, it means that queue is not full, then set
the value of rear to 0 and insert the new element there.
There are two cases in which the element cannot be inserted:
● When front ==0 && rear = max-1, which means that front is at the first
position of the Queue and rear is at the last position of the Queue.
● front== rear + 1;
Prof Jeenal
Algorithm to insert an element in a circular queue
Prof Jeenal
Algorithm to delete an element from the circular queue
Step 1: IF FRONT = -1
Write " UNDERFLOW "
Goto Step 4
[END of IF]
Step 2: SET VAL = QUEUE[FRONT]
Step 3: IF FRONT = REAR
SET FRONT = REAR = -1
ELSE
SET FRONT = (FRONT + 1)% MAX
[END of IF]
Step 4: EXIT
Prof Jeenal
Code to insert an element in a circular queue
#include <stdio.h>
#define MAX 5 // maximum size of queue
int queue[MAX];
int front = -1, rear = -1;
Prof Jeenal
Priority Queue
Prof Jeenal
Properties of Priority Queue
Prof Jeenal
How is Priority assigned to the elements in a Priority Queue?
Prof Jeenal
Types of Priority Queue:
Prof Jeenal
Types of Priority Queue:
Prof Jeenal
Types of Priority Queue:
Prof Jeenal
Difference between Priority Queue and Normal Queue?
● CPU Scheduling
● Graph algorithms like Dijkstra’s shortest path algorithm, Prim’s
Minimum Spanning Tree, etc.
● Stack Implementation
● All queue applications where priority is involved.
● Data compression in Huffman code
● Event-driven simulation such as customers waiting in a queue.
● Finding Kth largest/smallest element.
Prof Jeenal
Advantages of Priority Queue:
● It helps to access the elements in a faster way. This is because elements in a priority
queue are ordered by priority, one can easily retrieve the highest priority element
without having to search through the entire queue.
● The ordering of elements in a Priority Queue is done dynamically. Elements in a
priority queue can have their priority values updated, which allows the queue to
dynamically reorder itself as priorities change.
● Efficient algorithms can be implemented. Priority queues are used in many
algorithms to improve their efficiency, such as Dijkstra’s algorithm for finding the
shortest path in a graph and the A* search algorithm for pathfinding.
● Included in real-time systems. This is because priority queues allow you to quickly
retrieve the highest priority element, they are often used in real-time systems where
time is of the essence.
Prof Jeenal
Disadvantages of Priority Queue:
● High complexity. Priority queues are more complex than simple data structures like
arrays and linked lists, and may be more difficult to implement and maintain.
● High consumption of memory. Storing the priority value for each element in a
priority queue can take up additional memory, which may be a concern in systems
with limited resources.
● It is not always the most efficient data structure. In some cases, other data structures
like heaps or binary search trees may be more efficient for certain operations, such as
finding the minimum or maximum element in the queue.
● At times it is less predictable:. This is because the order of elements in a priority
queue is determined by their priority values, the order in which elements are retrieved
may be less predictable than with other data structures like stacks or queues, which
follow a first-in, first-out (FIFO) or last-in, first-out (LIFO) order.
Prof Jeenal
Deque
Prof Jeenal
Deque
Prof Jeenal
Deque
● In deque, the addition can be performed toward one side, and the erasure
should be possible on another end. The queue adheres to the FIFO rule in
which the component is embedded toward one side and erased from
another end. Hence, we reason that the deque can likewise be
considered as the queue.
Prof Jeenal
Deque
Prof Jeenal
Deque
● Yield confined queue: The yield limited line implies that a few
limitations are applied to the erasure activity. In a yield limited queue,
the cancellation can be applied uniquely from one end, while the
inclusion is conceivable from the two finishes.
Prof Jeenal
Operations on Deque
Prof Jeenal
We can perform two additional procedure on dequeue:
isFull(): This capacity restores a genuine worth if the stack is full; else,
it restores a bogus worth.
isEmpty(): This capacity restores a genuine worth if the stack is
vacant; else it restores a bogus worth.
Prof Jeenal
Insertion at the front end
● In this operation, the element is inserted from the front end of the queue.
Before implementing the operation, we first have to check whether the
queue is full or not.
● If the queue is not full, then the element can be inserted from the front
end by using the below conditions -
If the queue is empty, both rear and front are initialized with 0. Now, both
will point to the first element.
Otherwise, check the position of the front if the front is less than 1 (front < 1),
then reinitialize it by front = n - 1, i.e., the last index of the array.
Prof Jeenal
Insertion at the front end
Prof Jeenal
Insertion at the rear end
● In this operation, the element is inserted from the rear end of the queue. Before
implementing the operation, we first have to check again whether the queue is full or
not.
● If the queue is not full, then the element can be inserted from the rear end by using
the below conditions -
If the queue is empty, both rear and front are initialized with 0. Now, both will point to the
first element.
Otherwise, increment the rear by 1. If the rear is at last index (or size - 1), then instead of
increasing it by 1, we have to make it equal to 0.
Prof Jeenal
Insertion at the rear end
Prof Jeenal
Deletion at the front end
Prof Jeenal
Deletion at the front end
Prof Jeenal
Deletion at the rear end
Prof Jeenal
Deletion at the rear end
Prof Jeenal
Application of deque
● Deque can be used as both stack and queue, as it supports both
operations.
● Deque can be used as a palindrome checker means that if we read the
string from both ends, the string would be the same.
● Task scheduler: Deques can be used to implement a task scheduler that
keeps track of tasks to be executed. Tasks can be added to the back of the
deque, and the scheduler can remove tasks from the front of the deque
and execute them.
● Multi-level undo/redo functionality: Deques can be used to implement
undo and redo functionality in applications. Each time a user performs an
action, the current state of the application is pushed onto the deque.
When the user undoes an action, the front of the deque is popped, and the
previous state is restored. Prof Jeenal
Application of circular Queue
● Memory management: The circular queue provides memory management. As we
have already seen that in linear queue, the memory is not managed very efficiently.
But in case of a circular queue, the memory is managed efficiently by placing the
elements in a location which is unused.
● CPU Scheduling: The operating system also uses the circular queue to insert the
processes and then execute them.
● Traffic system: In a computer-control traffic system, traffic light is one of the best
examples of the circular queue. Each light of traffic light gets ON one by one after
every j interval of time. Like red light gets ON for one minute then yellow light for
one minute and then green light. After green light, the red light gets ON.
Prof Jeenal
Applications of priority Queue
● Dijkstra’s Shortest Path Algorithm using priority queue: When the graph is stored
in the form of adjacency list or matrix, priority queue can be used to extract minimum
efficiently when implementing Dijkstra’s algorithm.
● Data compression : It is used in Huffman codes which is used to compresses data.
● Artificial Intelligence : A* Search Algorithm : The A* search algorithm finds the
shortest path between two vertices of a weighted graph, trying out the most promising
routes first.
● Operating systems: It is also used in Operating System for load balancing (load
balancing on server), interrupt handling.
● Robotics: Priority Queue is used in robotics to plan and execute tasks in a priority-
based manner.
● Medical systems: Priority queues are used in medical systems, such as triage
systems in emergency departments, to prioritize patients based on the urgency of their
condition.
Prof Jeenal