Normal queue: FIFO
Priority queues: retrieve data in accordance with the size of the element priority
The real world, many cases can jump the queue (based on weight right)
application:
Which enemy AI game first attack (according to the level of experience, how much blood, etc.)
The operating system handles applications
Selecting the first M elements of the N element
Can be resolved using a sort in O (NlogN)
It can be resolved using the priority queue in O (NlogM) (N and M greater the difference the more obvious optimization)
Top10 quick access to the most popular search keywords (Top K issue)
Asked median
Implemented priority queue using different data structures:
Common array enqueuing O (1), the team O (n)
Order of the array, enqueue O (n), the team O (1)
The efficiency of the heap into the team and the team is O (lgn)
For a total of N requests, order of the array or arrays general, the worst case O (n ^ 2), and the stack is O (nlgn)
Heap is a special tree, to be met:
1) is a complete binary tree
2) the value of each node must be greater than (or equal) value for each node in its subtree