Priority queue
1.Priority queue
When a certain element in a collection has the highest weightage or priority - a common use case is to process that first
The data structure you use to store elements where highest priority has to be processed cab be called a priority queue
At every step we access the element with the highest priority
2.Operations
Insert elements (along with priority information)
Access the highest priority element
Remove the highest priority element
3.Complexity
Unordered | Oredered | |
Insertion | can be anywhere in the list or array: O(1) | Requires finding the right position for the element based on priority: O(N) |
Access | Accessing the highest priority element requires going through all elements in the list: O(N) | Accessing the highest priority element is then easy: O(1) |
Remove | Removing the highest priority element requires going through all elements in the list: O(N) | Removing the highest priority element is straight forward: O(1) |
Last updated