Heaps Flashcards
A special queue where the key with the highest priority is found at one end
Used to schedule jobs on a computer shared among multiple users
Priority queues
1) the higher the key,
the greater the priority
2) the key indicates
the execution time (lower is faster)
Implementation of priority queues using a linked list
insert – O(1)
delete min – O(n)
Implementation of priority queues using a sorted linked list
insert – O(n)
delete min – O(1)
An array that we can view as a nearly complete binary tree
(Binary) Heap
The tree is full on all levels except possibly
the bottom level (which is filled from left to right)
Each node of the tree is
an element of the array
The number of elements in the heap stored in an attribute
Heap-size
If heap-size = 0,
heap is empty
Given a heap represented by an array 𝐴, the root of the tree is at
𝐴[1]
For any node at index 𝑖,
a. its parent is at
index i / 2
b. its left child is at
index 2𝑖
c. its right child is at
index 2𝑖 + 1
𝐴[𝑝𝑎𝑟𝑒𝑛𝑡(𝑖)] ≥ 𝐴[𝑖]
Max-heap