SlideShare a Scribd company logo
TOPIC:
QUEUESQuooooooooooooooos……………………
Contents:
• Introduction to Queues
• Basic features of Queues
• Operations on Queues
• Algorithms and representation of Queues
• Types of Queues
• Applications of Queues
• How Queue is different from Stack?
• References
DATA STRUCTURE
▪Data structure is a way of organization
of all data items that considers not only
the elements stored but also their
relationship to each other.
▪Data structure is a specialized format
for organizing and storing data.
▪Ex. English Dictionary (sorted words).
TYPE OF DATA STRUCTURE
QUEUE
S:
▪ Queue is Non- primitive Linear Data
structure.
▪ Queue is also an abstract data type(ADT).
▪ In queue the first element is inserted from
one end called REAR(also called tail).
▪ The deletion of existing element takes
place from the other end called as
FRONT(also called head).
BASIC FEATURES OF
QUEUE:
• Like Stack, Queue is also an ordered list of
elements of similar data types.
i.e. It is a collection of homogeneous elements.
• Queue is a FIFO( First in First Out ) structure.
i.e. - the element which is inserted first will be
removed first.
- the middle elements are logically
inaccessible.
• Queue is used for temporary storage of data
values.
OPERATIONS ON QUEUE:
Basic Operations:
• Queue operations may involve initializing or defining
the queue, utilizing it, and then completely erasing it
from the memory.
• Queue operations involve basically two main
operations as follows:
• enqueue() − add (store) an item to the queue.
For enqueing (or storing) data in the queue we take
help of rear pointer.
•dequeue() − remove (access) an item from the queue.
In queue, we always dequeue (or access) data, pointed
by front pointer.
•Init() - This function is used for initializing the queue.
•Front – This is used to get the front data item from the
queue.
•Rear - This is used to get the last data item from the
queue.
ALGORITHMS
OF
QUEUES
•.
• Queue can be implemented using an
Array, Stack or Linked List.
• The easiest way of implementing a queue
is by using an Array.
• Initially the head(FRONT) and the
tail(REAR) of the queue points at the first
index of the array (starting the index of
array from 0).
Conditions in Queue
• FRONT < 0 ( Queue is Empty )
• REAR = Size of Queue ( Queue is Full )
• FRONT < REAR ( Queue contains at least one
element )
• No of elements in queue is : ( REAR - FRONT ) +
1
Restriction in Queue
•We can not insert element directly at middle index
(position) in Queue and vice verse for deletion.
• Insertion operation possible at REAR end only and
deletion operation at FRONT end. To insert we
increment REAR and to delete we increment
FRONT.
Enqueue Operation:
The following steps should be taken to enqueue (insert)
data into a queue −
•Step1− Check if the queue is full.
•Step2− If the queue is full, produce overflow error and
exit.
•Step3− If the is not full increment the rear pointer
to point the next empty space.
•Step4− Add data element to the queue location, where
the rear is pointing.
•Step5− return success.
Procedure enqueue(data)
if queue is full
return overflow
endif
rear ← rear + 1
queue[rear] ← data
return true
end procedure
int enqueue(int data)
if(isfull())
return 0;
rear = rear + 1;
queue[rear] = data;
return 1;
end procedure
ALGORITH
M:
IMPLEMENTATIO
N :
The following steps are taken to perform dequeue
operation −
•Step 1 − Check if the queue is empty.
•Step 2 − If the queue is empty, produce underflow
error and exit.
•Step 3 − If the queue is not empty, access the data
where front is pointing.
•Step 4 − Increment front pointer to point to the next
available data element.
•Step 5 − Return success.
Dequeue Operation:
procedure dequeue
if queue is empty
return underflow
end if
data = queue[front]
front ← front + 1
return true
end procedure
int dequeue()
{
if(isempty())
return 0;
int data = queue[front];
front = front + 1;
return data;
}
Algorithm: Implementation:
Program to implement Queue using Array:
#include<stdio.h>
#include<conio.h>
#define SIZE 10
void enQueue(int);
void deQueue();
void display();
int queue[SIZE], front = -1, rear = -1;
void main()
{
int value, choice;
clrscr();
while(1){
printf("nn***** MENU *****n");
printf("1.Insertion n2.Deletion n3.Display n4.Exit“);
printf("nEnter your choice: ");
scanf("%d",&choice);
switch(choice){
case 1: printf("Enter the value to be insert: ");
scanf("%d",&value);
enQueue(value);
break;
case 2: deQueue();
break;
case 3: display();
break;
case 4: exit(0);
default: printf("nWrong selection!!! Try again!!!");
}
}
}
void enQueue(int value){
if(rear == SIZE-1)
printf("nQueue is Full!!! Insertion is not possible!!!");
else{
if(front == -1)
front = 0;
rear++;
queue[rear] = value;
printf("nInsertion success!!!");
}
}
void deQueue(){
if(front == rear)
printf("nQueue is Empty!!! Deletion is not possible!!!");
else{
printf("nDeleted : %d", queue[front]);
front++;
if(front == rear)
front = rear = -1;
}
}
void display(){
if(rear == -1)
printf("nQueue is Empty!!!");
else{
int i;
printf("nQueue elements are:n");
for(i=front; i<=rear; i++)
printf("%dt",queue[i]);
}
}
Output:
Array Representation of
Queues:
Linked-List Representation
of Queues:
Types
of
Queue:
Basically there are FOUR main types of
queue, they are
as follows:
• SIMPLE QUEUE
• CIRCULAR QUEUE
• PRIORITY QUEUE
• DEQUE
SIMPLE QUEUE:
• Simple queue defines the simple
operation of queue in which
insertion occurs at the REAR of
the queue and deletion occurs at
the FRONT of the queue.
REAR FRONT
CIRCULAR QUEUE:
• Circular queue are used to remove the
drawback of simple queue.
• Both the front and the rear pointers
wrap around to the beginning of the array.
• It is also called as “RING BUFFER”.
• It is an ADT (abstract data type) .
PRIORITY QUEUE:
• Priority queue is the collection of elements
where elements are stored according to their
priority levels.
• Inserting and deleting of elements from queue
is decided by the priority of the elements.
• An element of higher priority is processed first.
• The two elements of same priority is processed
on FCFS (First come First served )basis.
• An example of priority queue in computer
science occurs in timesharing system in which
the processes of higher priority is executed
before any process of lower priority.
•
There are two types of priority queue:
• Ascending priority queue : It is a collection of
items in to which items can be inserted arbitrarily
and from which only the smallest item can be
removed.
• Descending priority queue : It is similar but
allows deletion of only the largest item.
DEQUE QUEUE:
• Deque stands for double ended queue.
• Also known as head–tail linked list.
• Elements can be deleted or inserted at
either end.
TYPES OF DEQUE:
•Input restricted deques : It allows insertions at only one end
of the array or list but deletions allows at both ends.
•Output restricted deques : It allows deletions at only one end
of the array or list but insertions allow at both ends.
In Computer Science field:
• Scheduler: for controlling access to shared
resources.
• Round Robin scheduling
• Job scheduling
• Keyboard buffer
• Print lines of a document
• Recognizing Palindromes
• Shared resource usage(CPU ,memory
access)
• Simulation
Shared printer Usage
Job
In Real Life Scenario:
• Simulation of Real World Illustrations:
- Waiting in line.
- Waiting on hold for Tech support.
- Waiting for your turn in mess-hall.
- Computer Lab.
• Telephone Operators:
- queuing system for handling calls to toll-
free numbers.
Queue in a Bank
Computer Lab
HOW QUEUE
IS
DIFFERENT
FROM STACK?
References:
• “ Introduction to Algorithms ”
by Thomas H.
• mycodeschool Videos
• www.w3schools.com
• www.hackerearth.com
• www.tutorialspoint.com
ANY
QUESTIO
NS
Queues

More Related Content

What's hot

Linear and Binary search
Linear and Binary searchLinear and Binary search
Linear and Binary search
Nisha Soms
 
Queue as data_structure
Queue as data_structureQueue as data_structure
Queue as data_structure
eShikshak
 
SEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMSSEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMS
Gokul Hari
 
Insertion sort
Insertion sort Insertion sort
Insertion sort
Monalisa Patel
 
Circular queue
Circular queueCircular queue
Insertion sort
Insertion sortInsertion sort
Insertion sort
almaqboli
 
Stacks IN DATA STRUCTURES
Stacks IN DATA STRUCTURESStacks IN DATA STRUCTURES
Stacks IN DATA STRUCTURES
Sowmya Jyothi
 
Double ended queue
Double ended queueDouble ended queue
Double ended queue
jyoti_lakhani
 
Queues
QueuesQueues
Insertion sort
Insertion sortInsertion sort
Insertion sort
Abdelrahman Saleh
 
Queue - Data Structure - Notes
Queue - Data Structure - NotesQueue - Data Structure - Notes
Queue - Data Structure - Notes
Omprakash Chauhan
 
Data Structures with C Linked List
Data Structures with C Linked ListData Structures with C Linked List
Data Structures with C Linked List
Reazul Islam
 
Circular link list.ppt
Circular link list.pptCircular link list.ppt
Circular link list.ppt
Tirthika Bandi
 
Priority Queue in Data Structure
Priority Queue in Data StructurePriority Queue in Data Structure
Priority Queue in Data Structure
Meghaj Mallick
 
Hash table
Hash tableHash table
Hash table
Vu Tran
 
linked lists in data structures
linked lists in data structureslinked lists in data structures
linked lists in data structures
DurgaDeviCbit
 
Searching techniques in Data Structure And Algorithm
Searching techniques in Data Structure And AlgorithmSearching techniques in Data Structure And Algorithm
Searching techniques in Data Structure And Algorithm
03446940736
 
Queue
QueueQueue
Queue
Raj Sarode
 

What's hot (20)

Linear and Binary search
Linear and Binary searchLinear and Binary search
Linear and Binary search
 
Queue as data_structure
Queue as data_structureQueue as data_structure
Queue as data_structure
 
SEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMSSEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMS
 
Insertion sort
Insertion sort Insertion sort
Insertion sort
 
Circular queue
Circular queueCircular queue
Circular queue
 
Insertion sort
Insertion sortInsertion sort
Insertion sort
 
Stacks IN DATA STRUCTURES
Stacks IN DATA STRUCTURESStacks IN DATA STRUCTURES
Stacks IN DATA STRUCTURES
 
Double ended queue
Double ended queueDouble ended queue
Double ended queue
 
Queues
QueuesQueues
Queues
 
Insertion sort
Insertion sortInsertion sort
Insertion sort
 
Queue - Data Structure - Notes
Queue - Data Structure - NotesQueue - Data Structure - Notes
Queue - Data Structure - Notes
 
Data Structures with C Linked List
Data Structures with C Linked ListData Structures with C Linked List
Data Structures with C Linked List
 
Circular link list.ppt
Circular link list.pptCircular link list.ppt
Circular link list.ppt
 
Priority Queue in Data Structure
Priority Queue in Data StructurePriority Queue in Data Structure
Priority Queue in Data Structure
 
Sorting
SortingSorting
Sorting
 
Hash table
Hash tableHash table
Hash table
 
linked lists in data structures
linked lists in data structureslinked lists in data structures
linked lists in data structures
 
Linked list
Linked listLinked list
Linked list
 
Searching techniques in Data Structure And Algorithm
Searching techniques in Data Structure And AlgorithmSearching techniques in Data Structure And Algorithm
Searching techniques in Data Structure And Algorithm
 
Queue
QueueQueue
Queue
 

Similar to Queues

stack.pptx
stack.pptxstack.pptx
stack.pptx
mayankKatiyar17
 
queue.pptx
queue.pptxqueue.pptx
queue.pptx
Dr.Shweta
 
Queues
QueuesQueues
Queue ADT for data structure for computer
Queue ADT for data structure for computerQueue ADT for data structure for computer
Queue ADT for data structure for computer
abinathsabi
 
Data Structures
Data StructuresData Structures
Data Structures
Dr.Umadevi V
 
Stack and Queue.pptx
Stack and Queue.pptxStack and Queue.pptx
Stack and Queue.pptx
Ddushb
 
Ist year Msc,2nd sem module1
Ist year Msc,2nd sem module1Ist year Msc,2nd sem module1
Ist year Msc,2nd sem module1
blessyboban92
 
Data Structures 2
Data Structures 2Data Structures 2
Data Structures 2
Dr.Umadevi V
 
LEC4-DS ALGO.pdf
LEC4-DS  ALGO.pdfLEC4-DS  ALGO.pdf
LEC4-DS ALGO.pdf
MuhammadUmerIhtisham
 
Queue
QueueQueue
stacks and queues for public
stacks and queues for publicstacks and queues for public
stacks and queues for public
iqbalphy1
 
Stack and queue power point presentation data structure and algorithms Stack-...
Stack and queue power point presentation data structure and algorithms Stack-...Stack and queue power point presentation data structure and algorithms Stack-...
Stack and queue power point presentation data structure and algorithms Stack-...
abhaysingh19149
 
Queue AS an ADT (Abstract Data Type)
Queue AS an ADT (Abstract Data Type)Queue AS an ADT (Abstract Data Type)
Queue AS an ADT (Abstract Data Type)
Self-Employed
 
Ds stack & queue
Ds   stack & queueDs   stack & queue
Ds stack & queue
Sunipa Bera
 
Queue
QueueQueue
Stack in Sata Structure
Stack in Sata StructureStack in Sata Structure
Stack in Sata Structure
Muhazzab Chouhadry
 
Queue ppt
Queue pptQueue ppt
Queue ppt
SouravKumar328
 
Lesson 4 - Queue ADT.pdf
Lesson 4 - Queue ADT.pdfLesson 4 - Queue ADT.pdf
Lesson 4 - Queue ADT.pdf
LeandroJrErcia
 

Similar to Queues (20)

stack.pptx
stack.pptxstack.pptx
stack.pptx
 
queue.pptx
queue.pptxqueue.pptx
queue.pptx
 
Queues
QueuesQueues
Queues
 
2.1 STACK & QUEUE ADTS
2.1 STACK & QUEUE ADTS2.1 STACK & QUEUE ADTS
2.1 STACK & QUEUE ADTS
 
Queue ADT for data structure for computer
Queue ADT for data structure for computerQueue ADT for data structure for computer
Queue ADT for data structure for computer
 
Data Structures
Data StructuresData Structures
Data Structures
 
Stack and Queue.pptx
Stack and Queue.pptxStack and Queue.pptx
Stack and Queue.pptx
 
Ist year Msc,2nd sem module1
Ist year Msc,2nd sem module1Ist year Msc,2nd sem module1
Ist year Msc,2nd sem module1
 
Data Structures 2
Data Structures 2Data Structures 2
Data Structures 2
 
LEC4-DS ALGO.pdf
LEC4-DS  ALGO.pdfLEC4-DS  ALGO.pdf
LEC4-DS ALGO.pdf
 
Queue
QueueQueue
Queue
 
stacks and queues for public
stacks and queues for publicstacks and queues for public
stacks and queues for public
 
Stack and queue power point presentation data structure and algorithms Stack-...
Stack and queue power point presentation data structure and algorithms Stack-...Stack and queue power point presentation data structure and algorithms Stack-...
Stack and queue power point presentation data structure and algorithms Stack-...
 
Queue AS an ADT (Abstract Data Type)
Queue AS an ADT (Abstract Data Type)Queue AS an ADT (Abstract Data Type)
Queue AS an ADT (Abstract Data Type)
 
Ds stack & queue
Ds   stack & queueDs   stack & queue
Ds stack & queue
 
Queue
QueueQueue
Queue
 
Data structures
Data structuresData structures
Data structures
 
Stack in Sata Structure
Stack in Sata StructureStack in Sata Structure
Stack in Sata Structure
 
Queue ppt
Queue pptQueue ppt
Queue ppt
 
Lesson 4 - Queue ADT.pdf
Lesson 4 - Queue ADT.pdfLesson 4 - Queue ADT.pdf
Lesson 4 - Queue ADT.pdf
 

Recently uploaded

Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024
Massimo Talia
 
DESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docxDESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docx
FluxPrime1
 
space technology lecture notes on satellite
space technology lecture notes on satellitespace technology lecture notes on satellite
space technology lecture notes on satellite
ongomchris
 
Gen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdfGen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdf
gdsczhcet
 
ethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.pptethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.ppt
Jayaprasanna4
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
gerogepatton
 
English lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdfEnglish lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdf
BrazilAccount1
 
HYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generationHYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generation
Robbie Edward Sayers
 
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
R&R Consult
 
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdfTop 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Teleport Manpower Consultant
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
bakpo1
 
Cosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdfCosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdf
Kamal Acharya
 
MCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdfMCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdf
Osamah Alsalih
 
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdfGoverning Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
WENKENLI1
 
WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234
AafreenAbuthahir2
 
Hierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power SystemHierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power System
Kerry Sado
 
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation & Control
 
Standard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - NeometrixStandard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - Neometrix
Neometrix_Engineering_Pvt_Ltd
 
Architectural Portfolio Sean Lockwood
Architectural Portfolio Sean LockwoodArchitectural Portfolio Sean Lockwood
Architectural Portfolio Sean Lockwood
seandesed
 
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
thanhdowork
 

Recently uploaded (20)

Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024
 
DESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docxDESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docx
 
space technology lecture notes on satellite
space technology lecture notes on satellitespace technology lecture notes on satellite
space technology lecture notes on satellite
 
Gen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdfGen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdf
 
ethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.pptethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.ppt
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
 
English lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdfEnglish lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdf
 
HYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generationHYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generation
 
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
 
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdfTop 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
 
Cosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdfCosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdf
 
MCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdfMCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdf
 
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdfGoverning Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
 
WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234
 
Hierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power SystemHierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power System
 
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
 
Standard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - NeometrixStandard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - Neometrix
 
Architectural Portfolio Sean Lockwood
Architectural Portfolio Sean LockwoodArchitectural Portfolio Sean Lockwood
Architectural Portfolio Sean Lockwood
 
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
 

Queues

  • 1.
  • 3. Contents: • Introduction to Queues • Basic features of Queues • Operations on Queues • Algorithms and representation of Queues • Types of Queues • Applications of Queues • How Queue is different from Stack? • References
  • 4. DATA STRUCTURE ▪Data structure is a way of organization of all data items that considers not only the elements stored but also their relationship to each other. ▪Data structure is a specialized format for organizing and storing data. ▪Ex. English Dictionary (sorted words).
  • 5. TYPE OF DATA STRUCTURE
  • 6. QUEUE S: ▪ Queue is Non- primitive Linear Data structure. ▪ Queue is also an abstract data type(ADT). ▪ In queue the first element is inserted from one end called REAR(also called tail). ▪ The deletion of existing element takes place from the other end called as FRONT(also called head).
  • 7. BASIC FEATURES OF QUEUE: • Like Stack, Queue is also an ordered list of elements of similar data types. i.e. It is a collection of homogeneous elements. • Queue is a FIFO( First in First Out ) structure. i.e. - the element which is inserted first will be removed first. - the middle elements are logically inaccessible. • Queue is used for temporary storage of data values.
  • 8.
  • 9. OPERATIONS ON QUEUE: Basic Operations: • Queue operations may involve initializing or defining the queue, utilizing it, and then completely erasing it from the memory. • Queue operations involve basically two main operations as follows:
  • 10. • enqueue() − add (store) an item to the queue. For enqueing (or storing) data in the queue we take help of rear pointer. •dequeue() − remove (access) an item from the queue. In queue, we always dequeue (or access) data, pointed by front pointer. •Init() - This function is used for initializing the queue. •Front – This is used to get the front data item from the queue. •Rear - This is used to get the last data item from the queue.
  • 11.
  • 13. •. • Queue can be implemented using an Array, Stack or Linked List. • The easiest way of implementing a queue is by using an Array. • Initially the head(FRONT) and the tail(REAR) of the queue points at the first index of the array (starting the index of array from 0).
  • 14. Conditions in Queue • FRONT < 0 ( Queue is Empty ) • REAR = Size of Queue ( Queue is Full ) • FRONT < REAR ( Queue contains at least one element ) • No of elements in queue is : ( REAR - FRONT ) + 1 Restriction in Queue •We can not insert element directly at middle index (position) in Queue and vice verse for deletion. • Insertion operation possible at REAR end only and deletion operation at FRONT end. To insert we increment REAR and to delete we increment FRONT.
  • 15. Enqueue Operation: The following steps should be taken to enqueue (insert) data into a queue − •Step1− Check if the queue is full. •Step2− If the queue is full, produce overflow error and exit. •Step3− If the is not full increment the rear pointer to point the next empty space. •Step4− Add data element to the queue location, where the rear is pointing. •Step5− return success.
  • 16. Procedure enqueue(data) if queue is full return overflow endif rear ← rear + 1 queue[rear] ← data return true end procedure int enqueue(int data) if(isfull()) return 0; rear = rear + 1; queue[rear] = data; return 1; end procedure ALGORITH M: IMPLEMENTATIO N :
  • 17. The following steps are taken to perform dequeue operation − •Step 1 − Check if the queue is empty. •Step 2 − If the queue is empty, produce underflow error and exit. •Step 3 − If the queue is not empty, access the data where front is pointing. •Step 4 − Increment front pointer to point to the next available data element. •Step 5 − Return success. Dequeue Operation:
  • 18. procedure dequeue if queue is empty return underflow end if data = queue[front] front ← front + 1 return true end procedure int dequeue() { if(isempty()) return 0; int data = queue[front]; front = front + 1; return data; } Algorithm: Implementation:
  • 19. Program to implement Queue using Array: #include<stdio.h> #include<conio.h> #define SIZE 10 void enQueue(int); void deQueue(); void display(); int queue[SIZE], front = -1, rear = -1; void main() { int value, choice; clrscr(); while(1){ printf("nn***** MENU *****n"); printf("1.Insertion n2.Deletion n3.Display n4.Exit“); printf("nEnter your choice: "); scanf("%d",&choice); switch(choice){
  • 20. case 1: printf("Enter the value to be insert: "); scanf("%d",&value); enQueue(value); break; case 2: deQueue(); break; case 3: display(); break; case 4: exit(0); default: printf("nWrong selection!!! Try again!!!"); } } } void enQueue(int value){ if(rear == SIZE-1) printf("nQueue is Full!!! Insertion is not possible!!!"); else{ if(front == -1) front = 0; rear++; queue[rear] = value; printf("nInsertion success!!!");
  • 21. } } void deQueue(){ if(front == rear) printf("nQueue is Empty!!! Deletion is not possible!!!"); else{ printf("nDeleted : %d", queue[front]); front++; if(front == rear) front = rear = -1; } } void display(){ if(rear == -1) printf("nQueue is Empty!!!"); else{ int i; printf("nQueue elements are:n"); for(i=front; i<=rear; i++) printf("%dt",queue[i]); } }
  • 26. Basically there are FOUR main types of queue, they are as follows: • SIMPLE QUEUE • CIRCULAR QUEUE • PRIORITY QUEUE • DEQUE
  • 27. SIMPLE QUEUE: • Simple queue defines the simple operation of queue in which insertion occurs at the REAR of the queue and deletion occurs at the FRONT of the queue. REAR FRONT
  • 28. CIRCULAR QUEUE: • Circular queue are used to remove the drawback of simple queue. • Both the front and the rear pointers wrap around to the beginning of the array. • It is also called as “RING BUFFER”. • It is an ADT (abstract data type) .
  • 29. PRIORITY QUEUE: • Priority queue is the collection of elements where elements are stored according to their priority levels. • Inserting and deleting of elements from queue is decided by the priority of the elements. • An element of higher priority is processed first. • The two elements of same priority is processed on FCFS (First come First served )basis.
  • 30. • An example of priority queue in computer science occurs in timesharing system in which the processes of higher priority is executed before any process of lower priority. • There are two types of priority queue: • Ascending priority queue : It is a collection of items in to which items can be inserted arbitrarily and from which only the smallest item can be removed. • Descending priority queue : It is similar but allows deletion of only the largest item.
  • 31. DEQUE QUEUE: • Deque stands for double ended queue. • Also known as head–tail linked list. • Elements can be deleted or inserted at either end.
  • 32. TYPES OF DEQUE: •Input restricted deques : It allows insertions at only one end of the array or list but deletions allows at both ends. •Output restricted deques : It allows deletions at only one end of the array or list but insertions allow at both ends.
  • 33.
  • 34. In Computer Science field: • Scheduler: for controlling access to shared resources. • Round Robin scheduling • Job scheduling • Keyboard buffer • Print lines of a document • Recognizing Palindromes • Shared resource usage(CPU ,memory access) • Simulation
  • 36. In Real Life Scenario: • Simulation of Real World Illustrations: - Waiting in line. - Waiting on hold for Tech support. - Waiting for your turn in mess-hall. - Computer Lab. • Telephone Operators: - queuing system for handling calls to toll- free numbers.
  • 37. Queue in a Bank Computer Lab
  • 38.
  • 40.
  • 41. References: • “ Introduction to Algorithms ” by Thomas H. • mycodeschool Videos • www.w3schools.com • www.hackerearth.com • www.tutorialspoint.com