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

Class XI Computer Science Lesson 10 Queue Data Structure Session 2021-'22

The document provides an overview of Queue data structures, explaining their FIFO nature where elements are added at the rear and removed from the front. It details operations like Enqueue and Dequeue, along with limitations such as overflow and underflow conditions. Additionally, it discusses the complexity of operations and applications of queues in real-world scenarios, such as task scheduling and call center systems.

Uploaded by

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

Class XI Computer Science Lesson 10 Queue Data Structure Session 2021-'22

The document provides an overview of Queue data structures, explaining their FIFO nature where elements are added at the rear and removed from the front. It details operations like Enqueue and Dequeue, along with limitations such as overflow and underflow conditions. Additionally, it discusses the complexity of operations and applications of queues in real-world scenarios, such as task scheduling and call center systems.

Uploaded by

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

Class XI

Computer Science
Lesson 10
Queue Data Structure
Session 2021-‘22

Video Tutorial:

• Introduction to Queues
• Queue with animation

What is a Queue Data Structure?

Queue is also an abstract data type or a linear data structure, just like stack data structure,
in which the first element is inserted from one end called the REAR(also called tail), and the
removal of existing element takes place from the other end called as FRONT(also
called head).
This makes queue as FIFO(First in First Out) data structure, which means that element
inserted first will be removed first.

Which is exactly how queue system works in real world. If you go to a ticket counter to buy
movie tickets, and are first in the queue, then you will be the first one to get the tickets.
Same is the case with Queue data structure. Data inserted first, will leave the queue first.

The process to add an element into queue is called Enqueue and the process of removal of
an element from queue is called Dequeue.

Terminologies

• Enqueue means adding one item to the queue and happens at the rear end of queue
• Dequeue means removal of one item from the queue and happens at the front end
of the queue
• If the max size of queue is reached then the queue is said to be in Overflow condition
• If the queue has no items then queue is said to be in Underflow condition

Page 1 of 6
Class XI
Computer Science
Lesson 10
Queue Data Structure
Session 2021-‘22

How Queue Works:

• Two pointers called FRONT and REAR are used to keep track of the first and last
elements in the queue.
• When initializing the queue, we set the value of FRONT and REAR to -1.
• On enqueuing an element, we increase the value of REAR index and place the new
element in the position pointed to by REAR.
• On dequeuing an element, we return the value pointed to by FRONT and increase
the FRONT index.
• Before enqueuing, we check if the queue is already full.
• Before dequeuing, we check if the queue is already empty.
• When enqueuing the first element, we set the value of FRONT to 0.
• When dequeuing the last element, we reset the values of FRONT and REAR to -1.

Page 2 of 6
Class XI
Computer Science
Lesson 10
Queue Data Structure
Session 2021-‘22

Limitations with Queues:


Aftter multiple enqueing and dequeing, the size of the queue gets reduced and new
elements can't be added

Page 3 of 6
Class XI
Computer Science
Lesson 10
Queue Data Structure
Session 2021-‘22

The following is demonstrated in the image below :-

Page 4 of 6
Class XI
Computer Science
Lesson 10
Queue Data Structure
Session 2021-‘22

Complexity Analysis of Queue Operations


Just like Stack, in case of a Queue too, we know exactly, on which position new element will
be added and from where an element will be removed, hence both these operations
requires a single step.

• Enqueue: O(1)
• Dequeue: O(1)

Applications of Queue:
Queue, as the name suggests is used whenever we need to manage any group of objects in
an order in which the first one coming in, also gets out first while the others wait for their
turn, like in the following scenarios:

• Serving requests on a single shared resource, like a printer, CPU task scheduling etc.
• In real life scenario, Call Center phone systems uses Queues to hold people calling
them in an order, until a service representative is free.
• order as they arrive i.e First come first served.

Worksheet

1. Queue is an entity which can hold a maximum of 100 integers. The queue enables
the user to add integers from the rear and remove integers from the front. Define a
class Queue with the following details:

Class name : Queue


Data Members / instance variables:
Que[ ] : array to hold the integer elements
size : stores the size of the array
front : to point the index of the front
rear : to point the index of the rear

Page 5 of 6
Class XI
Computer Science
Lesson 10
Queue Data Structure
Session 2021-‘22

Member functions:
Queue (int mm) constructor to initialize the data
size = mm, front = 0, rear = 0
void addele(int v ) : to add integer from the rear if possible else display the message
“Overflow”
int delele( ) : returns elements from front if present, otherwise displays the message
“Underflow” and return -9999
void display ( ) : displays the array elements

Specify the class Queue giving details of ONLY the functions void addele(int) and int
delele( ). Assume that the other functions have been defined. The main function and
algorithm need NOT be written.

Page 6 of 6

You might also like