SlideShare une entreprise Scribd logo
QUEUE IN DATASTRUCTURE
(BASIC OPERATION)
BY,
LAKSHMI,
ASSISTANT PROFESSOR,
DEPARTMENT OF COMPUTER SCIENCE,
SRI ADI CHUNCHANAGIRI WOMEN’S COLLEGE, CUMBUM.
What is a Queue?
1. A queue can be defined as an ordered list which enables insert operations to be performed at
one end called REAR and delete operations to be performed at another end called FRONT.
• 2. Queue is referred to be as First In First Out list.
• 3. For example, people waiting in line for a rail ticket form a
queue.
Applications of Queue
• Queues are widely used as waiting lists for a single shared resource like printer,
disk, CPU.
• Queues are used in asynchronous transfer of data (where data is not being
transferred at the same rate between two processes) for eg. pipes, file IO, sockets.
• Queues are used as buffers in most of the applications like MP3 media player, CD
player, etc.
• Queue are used to maintain the play list in media players in order to add and
remove the songs from the play-list.
• Queues are used in operating systems for handling interrupts.
Complexity
Data
Structu
re
Time Complexity Space
Compl
eity
Average Worst Worst
Access Search Insertio
n
Deletio
n
Access Search Insertio
n
Deletio
n
Queue θ(n) θ(n) θ(1) θ(1) O(n) O(n) O(1) O(1) O(n)
Basic Operations for Queue in Data Structure
A queue is an object (an abstract data structure - ADT) that allows the following operations:
• Enqueue: Add an element to the end of the queue
• Dequeue: Remove an element from the front of the queue
• IsEmpty: Check if the queue is empty
• IsFull: Check if the queue is full
• Peek: Get the value of the front of the queue without removing it
Enqueue() Operation
The following steps should be followed to insert (enqueue) data element into a
queue -
• Step 1: Check if the queue is full.
• Step 2: If the queue is full, Overflow error.
• Step 3: If the queue is not full, increment the rear pointer to point to the next
available empty space.
• Step 4: Add the data element to the queue location where the rear is pointing.
• Step 5: Here, you have successfully added 7, 2, and -9.
Enqueue() Operation
Dequeue() Operation
Obtaining data from the queue comprises two subtasks: access the data where the
front is pointing and remove the data after access. You should take the following steps
to remove data from the queue -
• Step 1: Check if the queue is empty.
• Step 2: If the queue is empty, Underflow error.
• Step 3: If the queue is not empty, access the data where the front pointer is
pointing.
• Step 4: Increment front pointer to point to the next available data element.
• Step 5: Here, you have removed 7, 2, and -9 from the queue data structure.
Dequeue() Operation
Peek() Operation
This function helps in extracting the data element where the front is pointing without
removing it from the queue. The algorithm of Peek() function is as follows-
• Step 1: Check if the queue is empty.
• Step 2: If the queue is empty, return “Queue is Empty.”
• Step 3: If the queue is not empty, access the data where the front pointer is pointing.
• Step 4: Return data.
isFull() Operation
This function checks if the rear pointer is reached at MAXSIZE to determine that
the queue is full. The following steps are performed in the isFull() operation -
• Step 1: Check if rear == MAXSIZE - 1.
• Step 2: If they are equal, return “Queue is Full.”
• Step 3: If they are not equal, return “Queue is not Full.”
isNull() Operation
The algorithm of the isNull() operation is as follows -
• Step 1: Check if the rear and front are pointing to null memory space, i.e.,
-1.
• Step 2: If they are pointing to -1, return “Queue is empty.”
• Step 3: If they are not equal, return “Queue is not empty.”
Basic Queue Operation in DataStructure.pptx

Contenu connexe

Tendances

Stack data structure
Stack data structureStack data structure
Stack data structure
Tech_MX
 

Tendances (20)

Min priority queue
Min priority queueMin priority queue
Min priority queue
 
VCE Unit 03vv.pptx
VCE Unit 03vv.pptxVCE Unit 03vv.pptx
VCE Unit 03vv.pptx
 
Classification of datastructure.ppt
Classification of datastructure.pptClassification of datastructure.ppt
Classification of datastructure.ppt
 
DATA STRUCTURE - STACK
DATA STRUCTURE - STACKDATA STRUCTURE - STACK
DATA STRUCTURE - STACK
 
Chapter 8: tree data structure
Chapter 8:  tree data structureChapter 8:  tree data structure
Chapter 8: tree data structure
 
Binary search trees
Binary search treesBinary search trees
Binary search trees
 
Stack and queue
Stack and queueStack and queue
Stack and queue
 
Unit 4 queue
Unit   4 queueUnit   4 queue
Unit 4 queue
 
trees in data structure
trees in data structure trees in data structure
trees in data structure
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data Structure
 
STACK ( LIFO STRUCTURE) - Data Structure
STACK ( LIFO STRUCTURE) - Data StructureSTACK ( LIFO STRUCTURE) - Data Structure
STACK ( LIFO STRUCTURE) - Data Structure
 
Data structure by Digvijay
Data structure by DigvijayData structure by Digvijay
Data structure by Digvijay
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data Structure
 
Infix to Postfix Conversion Using Stack
Infix to Postfix Conversion Using StackInfix to Postfix Conversion Using Stack
Infix to Postfix Conversion Using Stack
 
Stack Data Structure
Stack Data StructureStack Data Structure
Stack Data Structure
 
Max Flow Problem
Max Flow ProblemMax Flow Problem
Max Flow Problem
 
Queue
QueueQueue
Queue
 
Stack data structure
Stack data structureStack data structure
Stack data structure
 
Unit I-Data structures stack & Queue
Unit I-Data structures stack & QueueUnit I-Data structures stack & Queue
Unit I-Data structures stack & Queue
 
1.4 expression tree
1.4 expression tree  1.4 expression tree
1.4 expression tree
 

Similaire à Basic Queue Operation in DataStructure.pptx

queueppt-191018053228 (1).pptx
queueppt-191018053228 (1).pptxqueueppt-191018053228 (1).pptx
queueppt-191018053228 (1).pptx
MeghaKulkarni27
 
Stacks-and-Queues.pdf
Stacks-and-Queues.pdfStacks-and-Queues.pdf
Stacks-and-Queues.pdf
TobyWtf
 

Similaire à Basic Queue Operation in DataStructure.pptx (20)

Algorithm and Data Structure - Queue
Algorithm and Data Structure - QueueAlgorithm and Data Structure - Queue
Algorithm and Data Structure - Queue
 
Queue
QueueQueue
Queue
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data Structure
 
queueppt-191018053228 (1).pptx
queueppt-191018053228 (1).pptxqueueppt-191018053228 (1).pptx
queueppt-191018053228 (1).pptx
 
Unit-ii-Queue ADT.pptx
Unit-ii-Queue ADT.pptxUnit-ii-Queue ADT.pptx
Unit-ii-Queue ADT.pptx
 
Queue ppt
Queue pptQueue ppt
Queue ppt
 
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)
 
Queues
Queues Queues
Queues
 
QUEUE PPT BY KULJIT SINGH.pptx
QUEUE PPT BY KULJIT SINGH.pptxQUEUE PPT BY KULJIT SINGH.pptx
QUEUE PPT BY KULJIT SINGH.pptx
 
Queue and its operations
Queue and its operationsQueue and its operations
Queue and its operations
 
Unit 3 Stacks and Queues.pptx
Unit 3 Stacks and Queues.pptxUnit 3 Stacks and Queues.pptx
Unit 3 Stacks and Queues.pptx
 
@Chapter 4 DSA Part II.pptx
@Chapter 4 DSA Part II.pptx@Chapter 4 DSA Part II.pptx
@Chapter 4 DSA Part II.pptx
 
Queues
QueuesQueues
Queues
 
01-Introduction of DSA-1.pptx
01-Introduction of DSA-1.pptx01-Introduction of DSA-1.pptx
01-Introduction of DSA-1.pptx
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data Structure
 
Queues
QueuesQueues
Queues
 
Stack and queue
Stack and queueStack and queue
Stack and queue
 
Data Structures
Data StructuresData Structures
Data Structures
 
unit 5 stack & queue.ppt
unit 5 stack & queue.pptunit 5 stack & queue.ppt
unit 5 stack & queue.ppt
 
Stacks-and-Queues.pdf
Stacks-and-Queues.pdfStacks-and-Queues.pdf
Stacks-and-Queues.pdf
 

Plus de LakshmiSamivel (13)

Greedy Algorithm for Computer Science.ppt
Greedy Algorithm for Computer Science.pptGreedy Algorithm for Computer Science.ppt
Greedy Algorithm for Computer Science.ppt
 
General methodin Data Structure for UG.pptx
General methodin Data Structure for UG.pptxGeneral methodin Data Structure for UG.pptx
General methodin Data Structure for UG.pptx
 
DIVIDE AND CONQUERMETHOD IN DATASTRUCTURE.pptx
DIVIDE AND CONQUERMETHOD IN DATASTRUCTURE.pptxDIVIDE AND CONQUERMETHOD IN DATASTRUCTURE.pptx
DIVIDE AND CONQUERMETHOD IN DATASTRUCTURE.pptx
 
Presentation DM.pptx
Presentation DM.pptxPresentation DM.pptx
Presentation DM.pptx
 
Dos.pptx
Dos.pptxDos.pptx
Dos.pptx
 
Formatting tags
Formatting tagsFormatting tags
Formatting tags
 
Top down parsing
Top down parsingTop down parsing
Top down parsing
 
Semaphore
Semaphore Semaphore
Semaphore
 
Firewall ppt
Firewall pptFirewall ppt
Firewall ppt
 
View
ViewView
View
 
Procedures andcursors
Procedures andcursorsProcedures andcursors
Procedures andcursors
 
Computer network notes
Computer network notesComputer network notes
Computer network notes
 
OsI reference model
OsI reference modelOsI reference model
OsI reference model
 

Dernier

Industrial Training Report- AKTU Industrial Training Report
Industrial Training Report- AKTU Industrial Training ReportIndustrial Training Report- AKTU Industrial Training Report
Industrial Training Report- AKTU Industrial Training Report
Avinash Rai
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
CarlosHernanMontoyab2
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
plant breeding methods in asexually or clonally propagated crops
plant breeding methods in asexually or clonally propagated cropsplant breeding methods in asexually or clonally propagated crops
plant breeding methods in asexually or clonally propagated crops
parmarsneha2
 

Dernier (20)

MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
 
Industrial Training Report- AKTU Industrial Training Report
Industrial Training Report- AKTU Industrial Training ReportIndustrial Training Report- AKTU Industrial Training Report
Industrial Training Report- AKTU Industrial Training Report
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
 
Benefits and Challenges of Using Open Educational Resources
Benefits and Challenges of Using Open Educational ResourcesBenefits and Challenges of Using Open Educational Resources
Benefits and Challenges of Using Open Educational Resources
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
 
NCERT Solutions Power Sharing Class 10 Notes pdf
NCERT Solutions Power Sharing Class 10 Notes pdfNCERT Solutions Power Sharing Class 10 Notes pdf
NCERT Solutions Power Sharing Class 10 Notes pdf
 
NLC-2024-Orientation-for-RO-SDO (1).pptx
NLC-2024-Orientation-for-RO-SDO (1).pptxNLC-2024-Orientation-for-RO-SDO (1).pptx
NLC-2024-Orientation-for-RO-SDO (1).pptx
 
plant breeding methods in asexually or clonally propagated crops
plant breeding methods in asexually or clonally propagated cropsplant breeding methods in asexually or clonally propagated crops
plant breeding methods in asexually or clonally propagated crops
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 

Basic Queue Operation in DataStructure.pptx

  • 1. QUEUE IN DATASTRUCTURE (BASIC OPERATION) BY, LAKSHMI, ASSISTANT PROFESSOR, DEPARTMENT OF COMPUTER SCIENCE, SRI ADI CHUNCHANAGIRI WOMEN’S COLLEGE, CUMBUM.
  • 2. What is a Queue? 1. A queue can be defined as an ordered list which enables insert operations to be performed at one end called REAR and delete operations to be performed at another end called FRONT. • 2. Queue is referred to be as First In First Out list. • 3. For example, people waiting in line for a rail ticket form a queue.
  • 3.
  • 4. Applications of Queue • Queues are widely used as waiting lists for a single shared resource like printer, disk, CPU. • Queues are used in asynchronous transfer of data (where data is not being transferred at the same rate between two processes) for eg. pipes, file IO, sockets. • Queues are used as buffers in most of the applications like MP3 media player, CD player, etc. • Queue are used to maintain the play list in media players in order to add and remove the songs from the play-list. • Queues are used in operating systems for handling interrupts.
  • 5. Complexity Data Structu re Time Complexity Space Compl eity Average Worst Worst Access Search Insertio n Deletio n Access Search Insertio n Deletio n Queue θ(n) θ(n) θ(1) θ(1) O(n) O(n) O(1) O(1) O(n)
  • 6. Basic Operations for Queue in Data Structure A queue is an object (an abstract data structure - ADT) that allows the following operations: • Enqueue: Add an element to the end of the queue • Dequeue: Remove an element from the front of the queue • IsEmpty: Check if the queue is empty • IsFull: Check if the queue is full • Peek: Get the value of the front of the queue without removing it
  • 7. Enqueue() Operation The following steps should be followed to insert (enqueue) data element into a queue - • Step 1: Check if the queue is full. • Step 2: If the queue is full, Overflow error. • Step 3: If the queue is not full, increment the rear pointer to point to the next available empty space. • Step 4: Add the data element to the queue location where the rear is pointing. • Step 5: Here, you have successfully added 7, 2, and -9.
  • 9. Dequeue() Operation Obtaining data from the queue comprises two subtasks: access the data where the front is pointing and remove the data after access. You should take the following steps to remove data from the queue - • Step 1: Check if the queue is empty. • Step 2: If the queue is empty, Underflow error. • Step 3: If the queue is not empty, access the data where the front pointer is pointing. • Step 4: Increment front pointer to point to the next available data element. • Step 5: Here, you have removed 7, 2, and -9 from the queue data structure.
  • 11. Peek() Operation This function helps in extracting the data element where the front is pointing without removing it from the queue. The algorithm of Peek() function is as follows- • Step 1: Check if the queue is empty. • Step 2: If the queue is empty, return “Queue is Empty.” • Step 3: If the queue is not empty, access the data where the front pointer is pointing. • Step 4: Return data.
  • 12. isFull() Operation This function checks if the rear pointer is reached at MAXSIZE to determine that the queue is full. The following steps are performed in the isFull() operation - • Step 1: Check if rear == MAXSIZE - 1. • Step 2: If they are equal, return “Queue is Full.” • Step 3: If they are not equal, return “Queue is not Full.”
  • 13. isNull() Operation The algorithm of the isNull() operation is as follows - • Step 1: Check if the rear and front are pointing to null memory space, i.e., -1. • Step 2: If they are pointing to -1, return “Queue is empty.” • Step 3: If they are not equal, return “Queue is not empty.”