|
| 1 | +<p align='center'> |
| 2 | +<img width=60% src="../Priority Queue/Images/priority.jpg"> |
| 3 | +</p> |
| 4 | + |
| 5 | +## Overview: |
| 6 | +A unique kind of queue called a priority queue has elements that are each assigned a priority value. Additionally, components are treated according to their importance. In other words, more important factors come first. |
| 7 | + |
| 8 | +## What is Priority Queue? |
| 9 | +There must be a priority assigned to each item in the queue. |
| 10 | +Depending on the priority order chosen by the user—that is, whether the user considers a lower number to be higher priority or a higher number to be greater priority—higher or lower priority items must be dequeued before lower or higher priority elements, respectively. |
| 11 | +The first element that entered the priority queue first will be the first to be deleted if two items in the queue have the same priority value. This is known as the first in, first out, rule. |
| 12 | + |
| 13 | +## Types of Priority Queue |
| 14 | +#### Ascending Order Priority Queue: |
| 15 | +The items in the priority queue must be similar, which means they must be either less than, equal to, or higher than one another, as was previously stated. All the components are compared to one another in an ascending order priority queue according to the following rule. The priority is applied with a higher priority to smaller elements (or numbers). |
| 16 | + |
| 17 | +#### Descending Order Priority Queue: |
| 18 | +All the components are compared to one another in descending order priority queue according to the following rule. The priority increases with the size of the element (or number). Eaual to one another or larger than it. All the components are compared to one another in an ascending order priority queue according to the following rule. The priority is applied with a higher priority to smaller elements (or numbers). |
| 19 | + |
| 20 | +## Why are Heaps preferred over Binary Search Trees? |
| 21 | +While the Self Balancing BST requires O(nLogn) time, heap construction may be completed in O(N) time. Pointers are not used anymore since heaps are built via arrays. |
| 22 | + |
| 23 | +## Application of Priority Queue |
| 24 | +* Djikstra's Algorithm uses t to determine the shortest route between graph nodes. |
| 25 | +* In order to determine the Minimum Spanning Tree in a weighted undirected graph, it is employed in Prim's Algorithm. |
| 26 | +* Heap Sort uses it to order the heap data structure. |
| 27 | +* It is employed in the data compression algorithm Huffman Coding. |
| 28 | + |
| 29 | +## Complexity of Priority queue |
| 30 | +#### Time complexity: |
| 31 | +* Insertion : O(log n)O(logn) |
| 32 | +* Peek : O(1)O(1) |
| 33 | +* Deletion : O(log n)O(logn) |
| 34 | + |
| 35 | +## Read More |
| 36 | +To read more: [Click here](https://www.scaler.com/topics/data-structures/priority-queue-in-data-structure/) |
0 commit comments