SlideShare a Scribd company logo
1 of 18
 Queses:
 Array and list representation,
 Operations (traversal, insertion and deletion)
 Priority queues and Deques:
 Array and List representations
Definition of Queue
A Queue is an ordered collection of items from which
items may be deleted at one end (called the front of the
queue) and into which items may be inserted at the other
end (the rear of the queue).
The first element inserted into the queue is the first
element to be removed. For this reason a queue is
sometimes called a FIFO (first-in first-out) list as opposed
to the stack, which is a LIFO (last-in first-out).
Queue
items[MAXQUEUE-
1]
. .
. .
. .
items[2] C
items[1] B
items[0] A Front=0
Rear=2
Insert an item A
A new item (A) is inserted at the Rear of the queue
items[MAXQUEUE
-1]
. .
. .
items[3]
items[2]
items[1]
items[0] A Front=0,
Rear=0
Insert an item B
A new item (B) is inserted at the Rear of the queue
items[MAXQUEUE
-1]
. .
. .
items[3]
items[2]
items[1] B Rear=1
items[0] A Front=0
Insert an item C
A new item (C) is inserted at the Rear of the queue
items[MAXQUEUE
-1]
. .
. .
items[3]
items[2] C Rear=2
items[1] B
items[0] A Front=0
Insert an item D
A new item (D) is inserted at the Rear of the
queue
items[MAXQUEUE-
1]
. .
. .
items[3] D Rear=3
items[2] C
items[1] B
items[0] A Front=0
Insert Operation(Array)
QINSERT(QUEUE, N, FRONT, REAR, ITEM)
1. If FRONT = 1 and REAR = N, or FRONT = REAR + 1, then :
write OVERFLOW, and Return.
2. If FRONT = NULL, then:
Set FRONT := 1 and REAR := 1.
Else if REAR = N, then:
Set REAR := 1.
Else :
Set REAR := REAR + 1.
3. Set QUEUE[REAR]:= ITEM.
4. Return.
Delete A
An item (A) is deleted from the Front of the queue
items[MAXQUEUE-1]
. .
. .
items[3] D Rear=3
items[2] C
items[1] B Front=1
items[0] A
Delete B
An item (B) is deleted from the Front of the
queue.
items[MAXQUEUE-1]
. .
. .
items[3] D Rear=3
items[2] C Front=2
items[1] B
items[0] A
Delete C
An item (C) is deleted from the Front of the
queue
items[MAXQUEUE-1]
. .
. .
items[3] D Front=Rear=3
items[2] C
items[1] B
items[0] A
Delete D
An item (A) is deleted from the Front of the
queue.
items[MAXQUEUE-1]
. .
items[3] D Front=Rear=-1
items[2] C
items[1] B
items[0] A
Delete Operation(Array)
QDELETE(QUEUE, N, FRONT, REAR, ITEM)
1. If FRONT = NULL then :
write: UNDERFLOW, and Return.
2. Set ITEM := QUEUE[FRONT].
3. If FRONT = REAR,
Set FRONT := NULL and REAR := NULL
Else if FRONT = N, then:
Set FRONT := 1.
Else :
Set FRONT := FRONT + 1.
4. Return.
Insert Operation(LL)
LINKQ_INSERT(INFO, LINK, FRONT, REAR, AVAIL, ITEM)
1. If AVAIL = NULL, then :
write OVERFLOW, and Exit.
2. Set NEW := AVAIL and AVAIL := LINK[AVAIL]
3. Set INFO[NEW]:= ITEM and LINK[NEW]=NULL
4. If (FRONT = NULL), FRONT := REAR := NEW
Else set LINK[REAR] := NEW and REAR := NEW
5. Exit
Delete Operation(LL)
LINKQ_DELETE(INFO, LINK, FRONT, REAR, AVAIL,
ITEM)
1. If FRONT = NULL, then :
write UNDERFLOW, and Exit.
2. Set TEMP := FRONT
3. Set ITEM :=INFO[TEMP]
4. FRONT :=LINK[TEMP]
5. LINK[TEMP] = AVAIL and AVAIL = TEMP
6. Exit
Priority Queue
More specialized data structure.
Similar to Queue, having front and rear.
Items are removed from the front.
Items are ordered by key value so that the item with the
lowest key (or highest) is always at the front.
Items are inserted in proper position to maintain the
order.
Deques
It is a double-ended queue.
Items can be inserted and deleted from either ends.
More versatile data structure than stack or queue.
E.g. policy-based application (e.g. low priority go to the
end, high go to the front)
Thank You

More Related Content

What's hot (20)

Stack Data Structure V1.0
Stack Data Structure V1.0Stack Data Structure V1.0
Stack Data Structure V1.0
 
STACK ( LIFO STRUCTURE) - Data Structure
STACK ( LIFO STRUCTURE) - Data StructureSTACK ( LIFO STRUCTURE) - Data Structure
STACK ( LIFO STRUCTURE) - Data Structure
 
My lectures circular queue
My lectures circular queueMy lectures circular queue
My lectures circular queue
 
Stacks queues
Stacks queuesStacks queues
Stacks queues
 
Stacks in Data Structure
Stacks in Data StructureStacks in Data Structure
Stacks in Data Structure
 
Algorithm: priority queue
Algorithm: priority queueAlgorithm: priority queue
Algorithm: priority queue
 
Data Structure (Queue)
Data Structure (Queue)Data Structure (Queue)
Data Structure (Queue)
 
QUEUE IN DATA STRUCTURE USING C
QUEUE IN DATA STRUCTURE USING CQUEUE IN DATA STRUCTURE USING C
QUEUE IN DATA STRUCTURE USING C
 
Stack and queue
Stack and queueStack and queue
Stack and queue
 
Queue
QueueQueue
Queue
 
Stacks in DATA STRUCTURE
Stacks in DATA STRUCTUREStacks in DATA STRUCTURE
Stacks in DATA STRUCTURE
 
STACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTURESTACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTURE
 
03 stacks and_queues_using_arrays
03 stacks and_queues_using_arrays03 stacks and_queues_using_arrays
03 stacks and_queues_using_arrays
 
Queue in Data Structure
Queue in Data Structure Queue in Data Structure
Queue in Data Structure
 
Application of Stack - Yadraj Meena
Application of Stack - Yadraj MeenaApplication of Stack - Yadraj Meena
Application of Stack - Yadraj Meena
 
Queues presentation
Queues presentationQueues presentation
Queues presentation
 
Queues in C++
Queues in C++Queues in C++
Queues in C++
 
2.3 graphs of functions
2.3 graphs of functions2.3 graphs of functions
2.3 graphs of functions
 
Stack Data Structure
Stack Data StructureStack Data Structure
Stack Data Structure
 
Queue
QueueQueue
Queue
 

Similar to Data Structure and Algorithms Queues

Similar to Data Structure and Algorithms Queues (20)

Queues.ppt
Queues.pptQueues.ppt
Queues.ppt
 
Queues & ITS TYPES
Queues & ITS TYPESQueues & ITS TYPES
Queues & ITS TYPES
 
4. Queues in Data Structure
4. Queues in Data Structure4. Queues in Data Structure
4. Queues in Data Structure
 
Queue
QueueQueue
Queue
 
Queues-and-CQueue-Implementation
Queues-and-CQueue-ImplementationQueues-and-CQueue-Implementation
Queues-and-CQueue-Implementation
 
Queue
QueueQueue
Queue
 
Bsc cs ii dfs u-2 linklist,stack,queue
Bsc cs ii  dfs u-2 linklist,stack,queueBsc cs ii  dfs u-2 linklist,stack,queue
Bsc cs ii dfs u-2 linklist,stack,queue
 
Bca ii dfs u-2 linklist,stack,queue
Bca ii  dfs u-2 linklist,stack,queueBca ii  dfs u-2 linklist,stack,queue
Bca ii dfs u-2 linklist,stack,queue
 
Mca ii dfs u-3 linklist,stack,queue
Mca ii dfs u-3 linklist,stack,queueMca ii dfs u-3 linklist,stack,queue
Mca ii dfs u-3 linklist,stack,queue
 
Data Structures by Maneesh Boddu
Data Structures by Maneesh BodduData Structures by Maneesh Boddu
Data Structures by Maneesh Boddu
 
6.queue
6.queue6.queue
6.queue
 
LEC4-DS ALGO.pdf
LEC4-DS  ALGO.pdfLEC4-DS  ALGO.pdf
LEC4-DS ALGO.pdf
 
Queue
QueueQueue
Queue
 
Computer Engineering Data Structure Queue.pptx
Computer Engineering Data Structure Queue.pptxComputer Engineering Data Structure Queue.pptx
Computer Engineering Data Structure Queue.pptx
 
Unit 2 linked list and queues
Unit 2   linked list and queuesUnit 2   linked list and queues
Unit 2 linked list and queues
 
2.1 Queue.pptx
2.1 Queue.pptx2.1 Queue.pptx
2.1 Queue.pptx
 
Lecture 7 data structures and algorithms
Lecture 7 data structures and algorithmsLecture 7 data structures and algorithms
Lecture 7 data structures and algorithms
 
Queue
QueueQueue
Queue
 
queue_final.pptx
queue_final.pptxqueue_final.pptx
queue_final.pptx
 
Queue
QueueQueue
Queue
 

More from ManishPrajapati78

Data Structure and Algorithms Binary Search Tree
Data Structure and Algorithms Binary Search TreeData Structure and Algorithms Binary Search Tree
Data Structure and Algorithms Binary Search TreeManishPrajapati78
 
Data Structure and Algorithms Binary Tree
Data Structure and Algorithms Binary TreeData Structure and Algorithms Binary Tree
Data Structure and Algorithms Binary TreeManishPrajapati78
 
Data Structure and Algorithms Merge Sort
Data Structure and Algorithms Merge SortData Structure and Algorithms Merge Sort
Data Structure and Algorithms Merge SortManishPrajapati78
 
Data Structure and Algorithms The Tower of Hanoi
Data Structure and Algorithms The Tower of HanoiData Structure and Algorithms The Tower of Hanoi
Data Structure and Algorithms The Tower of HanoiManishPrajapati78
 
Data Structure and Algorithms Linked List
Data Structure and Algorithms Linked ListData Structure and Algorithms Linked List
Data Structure and Algorithms Linked ListManishPrajapati78
 
Data Structure and Algorithms Sorting
Data Structure and Algorithms SortingData Structure and Algorithms Sorting
Data Structure and Algorithms SortingManishPrajapati78
 
Data Structure and Algorithms Arrays
Data Structure and Algorithms ArraysData Structure and Algorithms Arrays
Data Structure and Algorithms ArraysManishPrajapati78
 
Data Structure and Algorithms
Data Structure and Algorithms Data Structure and Algorithms
Data Structure and Algorithms ManishPrajapati78
 
Data Structure and Algorithms Hashing
Data Structure and Algorithms HashingData Structure and Algorithms Hashing
Data Structure and Algorithms HashingManishPrajapati78
 
Data Structure and Algorithms Graph Traversal
Data Structure and Algorithms Graph TraversalData Structure and Algorithms Graph Traversal
Data Structure and Algorithms Graph TraversalManishPrajapati78
 
Data Structure and Algorithms Graphs
Data Structure and Algorithms GraphsData Structure and Algorithms Graphs
Data Structure and Algorithms GraphsManishPrajapati78
 
Data Structure and Algorithms Huffman Coding Algorithm
Data Structure and Algorithms Huffman Coding AlgorithmData Structure and Algorithms Huffman Coding Algorithm
Data Structure and Algorithms Huffman Coding AlgorithmManishPrajapati78
 
Data Structure and Algorithms Heaps and Trees
Data Structure and Algorithms Heaps and TreesData Structure and Algorithms Heaps and Trees
Data Structure and Algorithms Heaps and TreesManishPrajapati78
 
Data Structure and Algorithms AVL Trees
Data Structure and Algorithms AVL TreesData Structure and Algorithms AVL Trees
Data Structure and Algorithms AVL TreesManishPrajapati78
 

More from ManishPrajapati78 (14)

Data Structure and Algorithms Binary Search Tree
Data Structure and Algorithms Binary Search TreeData Structure and Algorithms Binary Search Tree
Data Structure and Algorithms Binary Search Tree
 
Data Structure and Algorithms Binary Tree
Data Structure and Algorithms Binary TreeData Structure and Algorithms Binary Tree
Data Structure and Algorithms Binary Tree
 
Data Structure and Algorithms Merge Sort
Data Structure and Algorithms Merge SortData Structure and Algorithms Merge Sort
Data Structure and Algorithms Merge Sort
 
Data Structure and Algorithms The Tower of Hanoi
Data Structure and Algorithms The Tower of HanoiData Structure and Algorithms The Tower of Hanoi
Data Structure and Algorithms The Tower of Hanoi
 
Data Structure and Algorithms Linked List
Data Structure and Algorithms Linked ListData Structure and Algorithms Linked List
Data Structure and Algorithms Linked List
 
Data Structure and Algorithms Sorting
Data Structure and Algorithms SortingData Structure and Algorithms Sorting
Data Structure and Algorithms Sorting
 
Data Structure and Algorithms Arrays
Data Structure and Algorithms ArraysData Structure and Algorithms Arrays
Data Structure and Algorithms Arrays
 
Data Structure and Algorithms
Data Structure and Algorithms Data Structure and Algorithms
Data Structure and Algorithms
 
Data Structure and Algorithms Hashing
Data Structure and Algorithms HashingData Structure and Algorithms Hashing
Data Structure and Algorithms Hashing
 
Data Structure and Algorithms Graph Traversal
Data Structure and Algorithms Graph TraversalData Structure and Algorithms Graph Traversal
Data Structure and Algorithms Graph Traversal
 
Data Structure and Algorithms Graphs
Data Structure and Algorithms GraphsData Structure and Algorithms Graphs
Data Structure and Algorithms Graphs
 
Data Structure and Algorithms Huffman Coding Algorithm
Data Structure and Algorithms Huffman Coding AlgorithmData Structure and Algorithms Huffman Coding Algorithm
Data Structure and Algorithms Huffman Coding Algorithm
 
Data Structure and Algorithms Heaps and Trees
Data Structure and Algorithms Heaps and TreesData Structure and Algorithms Heaps and Trees
Data Structure and Algorithms Heaps and Trees
 
Data Structure and Algorithms AVL Trees
Data Structure and Algorithms AVL TreesData Structure and Algorithms AVL Trees
Data Structure and Algorithms AVL Trees
 

Recently uploaded

Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 

Recently uploaded (20)

Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 

Data Structure and Algorithms Queues

  • 1.  Queses:  Array and list representation,  Operations (traversal, insertion and deletion)  Priority queues and Deques:  Array and List representations
  • 2. Definition of Queue A Queue is an ordered collection of items from which items may be deleted at one end (called the front of the queue) and into which items may be inserted at the other end (the rear of the queue). The first element inserted into the queue is the first element to be removed. For this reason a queue is sometimes called a FIFO (first-in first-out) list as opposed to the stack, which is a LIFO (last-in first-out).
  • 3. Queue items[MAXQUEUE- 1] . . . . . . items[2] C items[1] B items[0] A Front=0 Rear=2
  • 4. Insert an item A A new item (A) is inserted at the Rear of the queue items[MAXQUEUE -1] . . . . items[3] items[2] items[1] items[0] A Front=0, Rear=0
  • 5. Insert an item B A new item (B) is inserted at the Rear of the queue items[MAXQUEUE -1] . . . . items[3] items[2] items[1] B Rear=1 items[0] A Front=0
  • 6. Insert an item C A new item (C) is inserted at the Rear of the queue items[MAXQUEUE -1] . . . . items[3] items[2] C Rear=2 items[1] B items[0] A Front=0
  • 7. Insert an item D A new item (D) is inserted at the Rear of the queue items[MAXQUEUE- 1] . . . . items[3] D Rear=3 items[2] C items[1] B items[0] A Front=0
  • 8. Insert Operation(Array) QINSERT(QUEUE, N, FRONT, REAR, ITEM) 1. If FRONT = 1 and REAR = N, or FRONT = REAR + 1, then : write OVERFLOW, and Return. 2. If FRONT = NULL, then: Set FRONT := 1 and REAR := 1. Else if REAR = N, then: Set REAR := 1. Else : Set REAR := REAR + 1. 3. Set QUEUE[REAR]:= ITEM. 4. Return.
  • 9. Delete A An item (A) is deleted from the Front of the queue items[MAXQUEUE-1] . . . . items[3] D Rear=3 items[2] C items[1] B Front=1 items[0] A
  • 10. Delete B An item (B) is deleted from the Front of the queue. items[MAXQUEUE-1] . . . . items[3] D Rear=3 items[2] C Front=2 items[1] B items[0] A
  • 11. Delete C An item (C) is deleted from the Front of the queue items[MAXQUEUE-1] . . . . items[3] D Front=Rear=3 items[2] C items[1] B items[0] A
  • 12. Delete D An item (A) is deleted from the Front of the queue. items[MAXQUEUE-1] . . items[3] D Front=Rear=-1 items[2] C items[1] B items[0] A
  • 13. Delete Operation(Array) QDELETE(QUEUE, N, FRONT, REAR, ITEM) 1. If FRONT = NULL then : write: UNDERFLOW, and Return. 2. Set ITEM := QUEUE[FRONT]. 3. If FRONT = REAR, Set FRONT := NULL and REAR := NULL Else if FRONT = N, then: Set FRONT := 1. Else : Set FRONT := FRONT + 1. 4. Return.
  • 14. Insert Operation(LL) LINKQ_INSERT(INFO, LINK, FRONT, REAR, AVAIL, ITEM) 1. If AVAIL = NULL, then : write OVERFLOW, and Exit. 2. Set NEW := AVAIL and AVAIL := LINK[AVAIL] 3. Set INFO[NEW]:= ITEM and LINK[NEW]=NULL 4. If (FRONT = NULL), FRONT := REAR := NEW Else set LINK[REAR] := NEW and REAR := NEW 5. Exit
  • 15. Delete Operation(LL) LINKQ_DELETE(INFO, LINK, FRONT, REAR, AVAIL, ITEM) 1. If FRONT = NULL, then : write UNDERFLOW, and Exit. 2. Set TEMP := FRONT 3. Set ITEM :=INFO[TEMP] 4. FRONT :=LINK[TEMP] 5. LINK[TEMP] = AVAIL and AVAIL = TEMP 6. Exit
  • 16. Priority Queue More specialized data structure. Similar to Queue, having front and rear. Items are removed from the front. Items are ordered by key value so that the item with the lowest key (or highest) is always at the front. Items are inserted in proper position to maintain the order.
  • 17. Deques It is a double-ended queue. Items can be inserted and deleted from either ends. More versatile data structure than stack or queue. E.g. policy-based application (e.g. low priority go to the end, high go to the front)