Q1. Why should we prefer priority queue over sorted list to handle the high priority tasks in time ?
Sol. Sorted list uses full ordering every time a new element is added and worst scenario would be O(n). Priority queue uses partial ordering where it takes O(log n) time. Priority queue will make the high priority elements available on the top of the queue always.
For information about full order and partial details please check the discrete mathematics.
Comments
Post a Comment