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 ...

Get Data Structures and Algorithms in Java, 2nd Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.