Chapter 16 — Keeping Your Priorities Straight with Heaps

0.0(0)
Studied by 0 people
call kaiCall Kai
Locked
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/28

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 8:05 PM on 7/29/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai
Chat

No analytics yet

Send a link to your students to track their progress

29 Terms

1
New cards
Heap
A tree-based data structure used to quickly access the highest-priority value
2
New cards
Priority queue
A structure where the highest-priority item is processed first
3
New cards
Max heap
A heap where the greatest value is always at the root
4
New cards
Root of heap
The top node that contains the highest-priority value
5
New cards
Heap condition
Every parent node must be greater than its child nodes in a max heap
6
New cards
Weak ordering
A heap is not fully sorted, but it keeps enough order to find the greatest value quickly
7
New cards
Complete tree
A tree filled from left to right with no gaps except possibly at the end
8
New cards
Why heaps stay balanced
New nodes are inserted at the next available last position
9
New cards
Last node
The final node in the heap’s left-to-right order
10
New cards
Problem of the last node
The challenge of consistently finding where the last node or next open spot is
11
New cards
Heap insertion
Add the new value at the next open last position, then trickle it up
12
New cards
Trickle up
Move a newly inserted value upward by swapping it with its parent until the heap condition is restored
13
New cards
Heap insertion Big O
O(log N), because the value may move up through the heap’s levels
14
New cards
Heap deletion
Remove the root node, replace it with the last node, then trickle the new root down
15
New cards
Trickle down
Move a value downward by swapping it with its larger child until the heap condition is restored
16
New cards
Heap deletion Big O
O(log N), because the new root may move down through the heap’s levels
17
New cards
Reading the highest-priority value
O(1), because it is always at the root
18
New cards
Searching a heap
O(N), because heaps are not designed for finding arbitrary values
19
New cards
Heap vs binary search tree
A BST keeps full searchable order, while a heap only keeps priority order
20
New cards
Heap vs ordered array
Ordered arrays have fast deletion but slow insertion; heaps keep both insertion and deletion fast
21
New cards
Why heaps are good priority queues
They quickly access the highest-priority item and keep insertion/deletion efficient
22
New cards
Array-based heap
A heap stored inside an array instead of linked tree nodes
23
New cards
Root index in array heap
Index 0
24
New cards
Left child formula
left child index = parent index * 2 + 1
25
New cards
Right child formula
right child index = parent index * 2 + 2
26
New cards
Parent formula
parent index = floor((child index - 1) / 2)
27
New cards
Why arrays work well for heaps
Array indexes make it easy to find parents, children, and the last node
28
New cards
Heap pop order
Repeatedly popping a max heap returns values from greatest to smallest
29
New cards
Main lesson of Chapter 16
Heaps are optimized for priority queues because they keep the highest-priority value accessible while supporting fast insertion and deleti