-
Notifications
You must be signed in to change notification settings - Fork 359
Closed
Labels
Description
The current Heap._checkInvariants method doesn't fully validate the min-max invariants -- it just checks to see if the property holds for the immediate children of any node.
Instead, we should compare the value stored in every node with a currently expected range of values.
E.g., in the tree below, when checking descendants of 11, each value needs to be within the range 11 ... 41. Each new level narrows this range a bit further (by refining the lower or upper bounds, depending on the polarity of the node).
level 0: 8
level 1: 71 41
level 2: 31 10 11 16
level 3: 46 51 31 21 13
Implementing this would mean that we'd have to keep track of a stack of expected ranges in addition to their associated indices. (Or switch to a recursive implementation.)