Consider a situation of a boarding gate of a plane where passengers are allowed to board on the place based on their age. All passengers are on a line (queue) to board on the place, however, the oldest one is always allowed to board first no matter when he/she got in the line (queue). In this case, you cannot sort the passengers by their age, however, you know that oldest ones are always at the top of the line. This is an example of a priority queue where data will be accessed and processed based on their level of priority. Suppose you need to organize such type of data so that the data in highest priority can be accessed in a constant time, O(1). What type of data structure would you use in such cases? Justify your answer.
Consider a situation of a boarding gate of a plane where passengers are allowed to board on the place based on their age. All passengers are on a line (queue) to board on the place, however, the oldest one is always allowed to board first no matter when he/she got in the line (queue). In this case, you cannot sort the passengers by their age, however, you know that oldest ones are always at the top of the line. This is an example of a priority queue where data will be accessed and processed based on their level of priority. Suppose you need to organize such type of data so that the data in highest priority can be accessed in a constant time, O(1). What type of data structure would you use in such cases? Justify your answer.
Step by step
Solved in 2 steps