SlideShare une entreprise Scribd logo
1  sur  16
QUEUE
IN
DATA
STRUCTURE
PRESENTED BY-
MEHEDI HASAN
BATCH-D-74
INDEX
I. Introduction
II. Different types of Queue
III. Applications
IV. Conclusion
 Algorithms
 Working procedure
 Calculating Complexity
 Advantage & Disadvantage
INDTODUCTION
Queue is linear data structure. It is a way of storing and
organizing data.
It follows the principle of “first in first out”
Queue Different types of Queue
Operations
Enqueue(): used to inert elements to the end of the Queue
Dequeue(): Remove elements from the frontal side
Isempty() : To check the Queue is empty or not
Peek() : Returns the element of the first at
the queue
Linear Queue Algorithms
Dequeue ():
• Check if the queue is empty
(front == rear == -1).
• If empty, display an underflow error.
• Otherwise, increment front by 1.
• Remove the element from the front position in
the array.
Complexity:
The time complexity of insertion, deletion and
peek operation is O(1). If resizing is necessary
(i.e., when the array is full), then the enqueue
operation may take O(n) time in the worst
case, where n is the current size of the queue.
In Linear Queue, an insertion
takes place from one end while
the deletion occurs from another end.
Algorithms of Linear Queue:
Set array – arr[i]
Set front and rear to -1 to signify an empty queue.
Enqueue ():
• Check if queue is full (rear == SIZE - 1).
• If full, display an overflow error.
• Otherwise, increment tail/rear by 1.
• Insert the element at rear position in the array.
Linear Queue Working procedure
Linear Queue Advantage and Disadvantage
SL
No.
Advantage Disadvantage
1 Simple Implementation Fixed Capacity in Array-based
Implementation
2 Efficient for FIFO Operations Memory Fragmentation in Array-based
Implementation
3 Constant Time Complexity for Basic
Operations
Inefficient Removal of Arbitrary
Elements/Limitation of implementation
4 Suitable for Applications with Limited
Memory
Not Suitable for Priority-based Operations
Priority Queue Algorithms
Dequeue ():
• Remove the element with the highest priority.
• Rearrange the array to fill the gap left by the
removed element.
Complexity:
The time complexity of insertion, deletion is
O(log n).
In Priority Queue elements are arranges based
on their priority (values). Priority queues can be
implemented using Linked List, Heap, Binary search
tree and Array based.
Algorithms of Array-based priority Queue:
Set array – arr[i]
Set front and rear to -1 to signify an empty queue.
Enqueue ():
• Add the element at the end of the array.
• If necessary, reorder the array to maintain the priority
order.
• This can be achieved by comparing the priority of the
newly added element with its parent and swapping if
necessary until the priority order is restored.
Priority Queue working procedure
Dequeue()
Enqueue()
7
6
D Queue Algorithms
Algorithm Pop_Back(deque):
1. If deque is empty, return an error.
2. Get the element from the tail node of the
deque.
3. If deque has only one node:
- Set both head and tail pointers to null.
4. Else:
- Set the previous node of the current tail as
the new tail.
- Set the next pointer of the new tail to null.
5. Decrement the size of the deque.
6. Return the element.
assume a deque implemented using
a doubly linked list
Algorithms of D-Queue:
Algorithm Push_Front(deque, element):
1. Create a new node with the given element.
2. If deque is empty:
- Set the new node as both the head and tail of the
deque.
3. Else:
- Set the previous pointer of the current head node
to point to the new node.
- Set the next pointer of the new node to point to the
current head node.
- Update the head of the deque to point to the new
node.
4. Increment the size of the deque.
D Queue Algorithms
Algorithm Pop_Front(deque):
1. If deque is empty, return an error.
2. Get the element from the head node of the
deque.
3. If deque has only one node:
- Set both head and tail pointers to null.
4. Else:
- Set the next node of the current head as the
new head.
- Set the previous pointer of the new head to
null.
5. Decrement the size of the deque.
6. Return the element.
assume a deque implemented using
a doubly linked list
Algorithms of D-Queue:
Algorithm Push_Back(deque, element):
1. Create a new node with the given element.
2. If deque is empty:
- Set the new node as both the head and tail of the
deque.
3. Else:
- Set the next pointer of the current tail node to
point to the new node.
- Set the previous pointer of the new node to point
to the current tail node.
- Update the tail of the deque to point to the
new node.
4. Increment the size of the deque.
D Queue Working procedure
Queue Applications of Queue
Operating Systems:
Task scheduling: Queues are used in operating systems to manage tasks and processes.
Print spooling: Print jobs are placed in a queue and processed in the order they are received.
Networking:
Network packet handling: Queues are used in network routers and switches to manage incoming and outgoing packets.
Data Structures:
Breadth-first search (BFS): Queues are used in graph traversal algorithms like BFS to explore nodes level by level.
Cache replacement policies: Queues are used in cache implementations to implement replacement policies like FIFO (First-
In-First-Out).
Web Servers:
Request handling: Queues are used in web servers to manage incoming HTTP requests.
Hardware Design:
CPU scheduling: Queues are used in computer architecture and CPU scheduling algorithms to manage the execution of
processes on a multi-core processor.
Queue Conclusion
There can be a lot of memory wastage in static queues, as no matter what is the size of the queue, the space
occupied by it remains the same.
Traversing a queue will delete the foremost element on each iteration, eventually, emptying the queue.
QUEUE in data-structure (classification, working procedure, Applications)

Contenu connexe

Similaire à QUEUE in data-structure (classification, working procedure, Applications)

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 in C
Data Structures in CData Structures in C
Data Structures in C
Jabs6
 

Similaire à QUEUE in data-structure (classification, working procedure, Applications) (20)

queue.pptx
queue.pptxqueue.pptx
queue.pptx
 
Introduction data structure
Introduction data structureIntroduction data structure
Introduction data structure
 
STACK.pptx
STACK.pptxSTACK.pptx
STACK.pptx
 
DS UNIT2QUEUES.pptx
DS UNIT2QUEUES.pptxDS UNIT2QUEUES.pptx
DS UNIT2QUEUES.pptx
 
Queue
QueueQueue
Queue
 
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
 
Unit ii linear data structures
Unit ii linear data structures Unit ii linear data structures
Unit ii linear data structures
 
Queues
Queues Queues
Queues
 
PriorityqDhruvBaswal.pptx
PriorityqDhruvBaswal.pptxPriorityqDhruvBaswal.pptx
PriorityqDhruvBaswal.pptx
 
Data Structures
Data StructuresData Structures
Data Structures
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data Structure
 
stack.pptx
stack.pptxstack.pptx
stack.pptx
 
Data Structures in C
Data Structures in CData Structures in C
Data Structures in C
 
Unit i(dsc++)
Unit i(dsc++)Unit i(dsc++)
Unit i(dsc++)
 
Unit 3 Stacks and Queues.pptx
Unit 3 Stacks and Queues.pptxUnit 3 Stacks and Queues.pptx
Unit 3 Stacks and Queues.pptx
 
Unit 1_Stack and Queue using Linked Organization.pdf
Unit 1_Stack and Queue using Linked Organization.pdfUnit 1_Stack and Queue using Linked Organization.pdf
Unit 1_Stack and Queue using Linked Organization.pdf
 
Data structure.ppt
Data structure.pptData structure.ppt
Data structure.ppt
 
Lesson 4 - Queue ADT.pdf
Lesson 4 - Queue ADT.pdfLesson 4 - Queue ADT.pdf
Lesson 4 - Queue ADT.pdf
 
Data structures
Data structuresData structures
Data structures
 
Unit 5 dsa QUEUE
Unit 5 dsa QUEUEUnit 5 dsa QUEUE
Unit 5 dsa QUEUE
 

Dernier

Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 

Dernier (20)

Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 

QUEUE in data-structure (classification, working procedure, Applications)

  • 2. INDEX I. Introduction II. Different types of Queue III. Applications IV. Conclusion  Algorithms  Working procedure  Calculating Complexity  Advantage & Disadvantage
  • 3. INDTODUCTION Queue is linear data structure. It is a way of storing and organizing data. It follows the principle of “first in first out”
  • 5. Operations Enqueue(): used to inert elements to the end of the Queue Dequeue(): Remove elements from the frontal side Isempty() : To check the Queue is empty or not Peek() : Returns the element of the first at the queue
  • 6. Linear Queue Algorithms Dequeue (): • Check if the queue is empty (front == rear == -1). • If empty, display an underflow error. • Otherwise, increment front by 1. • Remove the element from the front position in the array. Complexity: The time complexity of insertion, deletion and peek operation is O(1). If resizing is necessary (i.e., when the array is full), then the enqueue operation may take O(n) time in the worst case, where n is the current size of the queue. In Linear Queue, an insertion takes place from one end while the deletion occurs from another end. Algorithms of Linear Queue: Set array – arr[i] Set front and rear to -1 to signify an empty queue. Enqueue (): • Check if queue is full (rear == SIZE - 1). • If full, display an overflow error. • Otherwise, increment tail/rear by 1. • Insert the element at rear position in the array.
  • 8. Linear Queue Advantage and Disadvantage SL No. Advantage Disadvantage 1 Simple Implementation Fixed Capacity in Array-based Implementation 2 Efficient for FIFO Operations Memory Fragmentation in Array-based Implementation 3 Constant Time Complexity for Basic Operations Inefficient Removal of Arbitrary Elements/Limitation of implementation 4 Suitable for Applications with Limited Memory Not Suitable for Priority-based Operations
  • 9. Priority Queue Algorithms Dequeue (): • Remove the element with the highest priority. • Rearrange the array to fill the gap left by the removed element. Complexity: The time complexity of insertion, deletion is O(log n). In Priority Queue elements are arranges based on their priority (values). Priority queues can be implemented using Linked List, Heap, Binary search tree and Array based. Algorithms of Array-based priority Queue: Set array – arr[i] Set front and rear to -1 to signify an empty queue. Enqueue (): • Add the element at the end of the array. • If necessary, reorder the array to maintain the priority order. • This can be achieved by comparing the priority of the newly added element with its parent and swapping if necessary until the priority order is restored.
  • 10. Priority Queue working procedure Dequeue() Enqueue() 7 6
  • 11. D Queue Algorithms Algorithm Pop_Back(deque): 1. If deque is empty, return an error. 2. Get the element from the tail node of the deque. 3. If deque has only one node: - Set both head and tail pointers to null. 4. Else: - Set the previous node of the current tail as the new tail. - Set the next pointer of the new tail to null. 5. Decrement the size of the deque. 6. Return the element. assume a deque implemented using a doubly linked list Algorithms of D-Queue: Algorithm Push_Front(deque, element): 1. Create a new node with the given element. 2. If deque is empty: - Set the new node as both the head and tail of the deque. 3. Else: - Set the previous pointer of the current head node to point to the new node. - Set the next pointer of the new node to point to the current head node. - Update the head of the deque to point to the new node. 4. Increment the size of the deque.
  • 12. D Queue Algorithms Algorithm Pop_Front(deque): 1. If deque is empty, return an error. 2. Get the element from the head node of the deque. 3. If deque has only one node: - Set both head and tail pointers to null. 4. Else: - Set the next node of the current head as the new head. - Set the previous pointer of the new head to null. 5. Decrement the size of the deque. 6. Return the element. assume a deque implemented using a doubly linked list Algorithms of D-Queue: Algorithm Push_Back(deque, element): 1. Create a new node with the given element. 2. If deque is empty: - Set the new node as both the head and tail of the deque. 3. Else: - Set the next pointer of the current tail node to point to the new node. - Set the previous pointer of the new node to point to the current tail node. - Update the tail of the deque to point to the new node. 4. Increment the size of the deque.
  • 13. D Queue Working procedure
  • 14. Queue Applications of Queue Operating Systems: Task scheduling: Queues are used in operating systems to manage tasks and processes. Print spooling: Print jobs are placed in a queue and processed in the order they are received. Networking: Network packet handling: Queues are used in network routers and switches to manage incoming and outgoing packets. Data Structures: Breadth-first search (BFS): Queues are used in graph traversal algorithms like BFS to explore nodes level by level. Cache replacement policies: Queues are used in cache implementations to implement replacement policies like FIFO (First- In-First-Out). Web Servers: Request handling: Queues are used in web servers to manage incoming HTTP requests. Hardware Design: CPU scheduling: Queues are used in computer architecture and CPU scheduling algorithms to manage the execution of processes on a multi-core processor.
  • 15. Queue Conclusion There can be a lot of memory wastage in static queues, as no matter what is the size of the queue, the space occupied by it remains the same. Traversing a queue will delete the foremost element on each iteration, eventually, emptying the queue.