0% found this document useful (0 votes)
2 views16 pages

Queue

This document provides an overview of queues, a linear data structure that operates on a First In, First Out (FIFO) basis, detailing its fundamental operations, types, and applications. It covers various queue types including Deques and Priority Queues, along with their respective applications in real-world scenarios. Additionally, it presents problem-solving examples and interview questions related to queues.

Uploaded by

kinkardinda70
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views16 pages

Queue

This document provides an overview of queues, a linear data structure that operates on a First In, First Out (FIFO) basis, detailing its fundamental operations, types, and applications. It covers various queue types including Deques and Priority Queues, along with their respective applications in real-world scenarios. Additionally, it presents problem-solving examples and interview questions related to queues.

Uploaded by

kinkardinda70
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 16

Fundamentals of

Data Structures
Learn, Apply and Build Projects

Topic: Queue

By
Mr. Ravi Kant Sahu
(Oracle Certified Associate, Java SE8 Programmer)
Assistant Professor, Lovely Professional University
Phagwara (Punjab)
Outlines
• Introduction
• Queue Fundamentals
• Queue Operations
• Types of Queues
• Problems on Queue
• Interview Questions

© Ravi Kant Sahu, Assistant Professor (Lovely Professional University, Punjab)


Queue
 A Queue is a linear data structure that follows the principle of "First
In, First Out" (FIFO).

 In Queue, deletions can take place only at one end, called the
‘FRONT’.

 In Queue, insertions can take place only at the other end, called the
‘REAR’.

© Ravi Kant Sahu, Assistant Professor (Lovely Professional University, Punjab)


Queue

© Ravi Kant Sahu, Assistant Professor (Lovely Professional University, Punjab)


Queue Operations
void enque(int queue[], int size, int front, int rear, int item)
{

© Ravi Kant Sahu, Assistant Professor (Lovely Professional University, Punjab)


Queue Operations
int deque(int queue[], int size, int front, int rear)
{

© Ravi Kant Sahu, Assistant Professor (Lovely Professional University, Punjab)


Applications of Queue
• Task Scheduling
• Resource Allocation
• Memory Management
• Breadth First Search
• Level Order Traversal of a Tree

© Ravi Kant Sahu, Assistant Professor (Lovely Professional University, Punjab)


Types of Queues
1. Deque (Double Ended Queue): allows insert and delete operations at
both ends.

Two variations of Deque are:


• Input-Restricted Deque:
allows insertion only at one end while deletion in both ends of the list.
• Output-Restricted Deque:
allows deletion only at one end while insertion at both the ends of the
list.

© Ravi Kant Sahu, Assistant Professor (Lovely Professional University, Punjab)


Applications of Deque

• Undo/Redo Functionality
• Browser History Navigation
• Cache Implementation

© Ravi Kant Sahu, Assistant Professor (Lovely Professional University, Punjab)


Types of Queues(2)
2. Priority Queue
A Priority Queue is a collection of elements such that each element has
been assigned a priority and such that the order in which elements are
processed comes from the following rules:
o An element of higher priority is processed before any element of lower
priority.

o Two elements with the same priority are processed according to the order in
which they were added to the queue.

© Ravi Kant Sahu, Assistant Professor (Lovely Professional University, Punjab)


Applications of Priority Queue

• CPU Scheduling
• Huffman Coding (Data Compression)
• Event-Driven Simulation Systems
• Task Scheduling in Real-Time Systems
• Load Balancing and Network Routing

© Ravi Kant Sahu, Assistant Professor (Lovely Professional University, Punjab)


Problem Solving-1
232. Implement Queue using Stacks

Implement a first in first out (FIFO) queue using only two stacks.
The implemented queue should support all the functions of a normal
queue (push, peek, pop, and empty).

© Ravi Kant Sahu, Assistant Professor (Lovely Professional University, Punjab)


Problem Solving-2
1700. Number of Students Unable to Eat Lunch

The school cafeteria offers circular and square sandwiches at lunch break, referred to by
numbers 0 and 1 respectively. All students stand in a queue. Each student either prefers
square or circular sandwiches.

The number of sandwiches in the cafeteria is equal to the number of students. The
sandwiches are placed in a stack. At each step:

If the student at the front of the queue prefers the sandwich on the top of the stack, they will
take it and leave the queue. Otherwise, they will leave it and go to the queue's end.

This continues until none of the queue students want to take the top sandwich and are thus
unable to eat.
© Ravi Kant Sahu, Assistant Professor (Lovely Professional University, Punjab)
Interview Questions

1. What are the uses of Deque?


2. What are the applications of a Queue?
3. What is the condition of Overflow in a Queue implemented using
Circular Array of size N?
4. What are the applications of Priority Queue?
5. How will you implement a Stack using Queues?

© Ravi Kant Sahu, Assistant Professor (Lovely Professional University, Punjab)


Student Feedback (Daily)
LPU Touch
Dashboard → Skill Development Feedback → Select Course
Code(PETV71) → Submit Feedback

UMS:
UMS Navigation-----LMS------Skill Development Feedback
(Select course code: PETV71) and fill the feedback

© Ravi Kant Sahu, Assistant Professor (Lovely Professional University, Punjab)


WhatsApp Group

© Ravi Kant Sahu, Assistant Professor (Lovely Professional University, Punjab)

You might also like