Skip to content

Changing a number in a heap

storing

Level 2 of 3

Also called Decrease-key, Increase-key, Change-key and Priority update.

A heap, smallest on top, where a number already inside can change. Look up where it stands, from the note the heap keeps, and write the new number there. If it got smaller it climbs, as a number put in does; if not, it sinks, as a number moved to the top does. Shortest paths and cheapest networks lean on this step.

the row

the row as a tree

comparisons
0
swaps
0

step 1 of 1

Examples

A number from 1 to 99 puts it in, a dash on its own takes the smallest out, and 47->5 changes a 47 in the heap to 5 (the first in the row, if there are two). Up to 12 of them, at most 7 put in, separated by commas or spaces, for example 31, 12, 47, 47->5.