September 2017
Intermediate to advanced
800 pages
23h 19m
English
Content preview from Data Structures and Algorithms in Java, 2nd EditionBecome an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
Start your free trial


12. Heaps
We saw in Chapter 4, “Stacks and Queues,” that a priority queue is a data structure that offers convenient access to the data item with the smallest (or largest) key.
Priority queues may be used for task scheduling in computers, where some programs and activities should be executed sooner than others and are therefore given a higher priority.
Another example is in weapons systems, say in a navy cruiser. Numerous threats—airplanes, missiles, submarines, and so on—are detected and must be prioritized. For example, a missile that’s a short distance from the cruiser is assigned a higher priority than an aircraft a long distance away so that countermeasures ...