![]() ![]() That is, it should be possible to order the data from least to highest priority or highest to least priority.Ī classic implementation of Priority Queue can be with Binary Heap.Īs the name suggests, in a binary heap, every node has at most two children. Note: Priority queue only supports the data which can be compared with each other. So far, priority queue is just like an Abstract Data Type which has to be implemented separately to get the desired order. This is a priority queue where each data in the queue has a certain priority and the data with highest priority goes out first and then the second and so on.įrom the above example, it can be seen that a simple queue cannot be used to implement a priority queue, where each data is associated with some weight. Now imagine, what if in that same queue, a celebrity joins in? Or may be the President of your country? Would that person be standing at the end of the queue now to wait for his turn? Well, in this circumstances, you might want them to go before you, despite the fact they joined last. Hence, a FIFO (or First In First Out) linear data structure. A simple queue, where the first person who joined it, will be the first one to leave it too. Starting with Priority Queue, let’s first understand what a simple queue is and how it is different from a Priority Queue.Ĭan think of a line where you had to stand, waiting for your turn to get your Pizza, or may be to get into a bus? That is a queue you are standing in. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |