Table of Contents

A More Complex Data Structure: Priority Queues

To qualitatively improve the brute-force algorithms so we can have efficient algorithms, we always need to overcome higher-level obstacles. However, the running time of polynomial-time algorithms can often be further improved through the implementation details and use of more complex data structures. Some of those complex data structures are usually specialized for solving some kind of problems, while we can also find others that are more general in their applications. This section illustrates and analyses a broadly used complex data structure, called priority queue. In a priority queue, each element is inserted with a certain key or value, which helps to identify the element for various manipulations. Priority queues perform non-trivial computations when called, and are usually a much better alternative to arrays and lists.

Problem

The following are situations where we may need to use priority queues:

Implementing the Priority queue

To implement a priority queue using:

The heap comes in as a solution to these issues, as it combines the benefits of a sorted array and a list. Elements in a heap order are arranged in such a way the key of any parent element is not bigger than the key of any of its children, and the heap itself is a balanced binary tree.

in a heap implemented using arrays:

Implementing the heap operations

(For definitions of too big and too small,see Tardos and Kleinberg, pp 61-4).

Implementing Priority Queues with Heaps

Operations used for a heap with N < n elements:

If we want to operate on a particular node,regardless of where it is positioned in the heap, we simply maintain an additional array Position that stores the current position of each element.

In this case,

I definitely need to remember the positional relationships between the parent and its children in a heap. I also need to remember the two procedures, namely Heapify-up and Heapify-down

This section was a very important and interesting reading, but I give it an 8/10 since it required additional attention compared to the other sections.