Degree-indexed root consolidation and extractMin for a Fibonacci heap #
This file proves the correctness, memory-safety, and O(log n) amortized instruction bound of
scatterRootCode and extractMinCode Fredman and Tarjan
Cormen et al., Section 19.2:
- Degree-table invariant (
SlotInv): Tracks the subsetslotTreesof consolidated root trees currently stored incons[0..maxDeg], maintaining pairwise-distinct degrees,maxDeg ≤ 2 * Nat.log 2 n + 1, and zeroing of all unoccupied entriescons[d](d ≤ n). - Root scattering (
scatterRootCode_exec): Repeatedly links equal-degree roots viaValidRoot.linkunder lexicographicIndexedMinPQ.PrioLTusing internal potential50 * slotTrees.length, executing int + 50 * slotTrees'.length ≤ 63 + 50 * slotTrees.lengthsteps while framing all other live nodes. - Minimum extraction (
extractMinCode_exec): Removesz = minRoot - 1(agreeing withIndexedMinPQ.findMin), scattersz's children and thenumRoots - 1remaining roots intocons, and scans only0 .. maxDeg(≤ 2 * Nat.log 2 n + 2slots) to rebuild the root circular list andminRootRegwhile restoringcons = 0int + potential y ≤ 410 * (Nat.log 2 n + 1) + potential xinstructions.
Main definitions #
Cslib.Algorithms.WordRAM.PriorityQueue.FibonacciHeap.SlotInv: consolidation-table invariant tracking distinct-degree root trees incons[0..maxDeg].
Main results #
Cslib.Algorithms.WordRAM.PriorityQueue.FibonacciHeap.scatterRootCode_exec: amortized root scattering and equal-degree linking specification.Cslib.Algorithms.WordRAM.PriorityQueue.FibonacciHeap.extractMinCode_exec:O(log n)amortizedextractMinspecification.
References #
Framing and pure-ℕ degree bounds during consolidation #
Framing ValidRoot st none T across a state transition preserving node fields on T.nodes and
pointer fields on strict descendants forestNodes T.children.
Framing ValidRoot st none T when all seven vertex arrays agree on T.nodes.
Every valid subtree T disjoint from at least one other handle z : Fin n satisfies both
T.deg ≤ 2 * Nat.log 2 n + 1 and T.deg + 2 ≤ n.
Framing SlotInv across a transition preserving cons and ValidRoot on slotTrees.
Lookup in st.cons d (d ≤ n): either st.cons d = 0 and no tree in slotTrees has degree
d, or a unique index i < slotTrees.length has (slotTrees[i]).deg = d and
st.cons d = (slotTrees[i]).root.val + 1.
Clearing slot d = (slotTrees[i]).deg (d ≤ n) removes slotTrees[i] from SlotInv.
Storing a consolidated tree T_cur of unoccupied degree d into st.cons d and updating
maxDeg to max maxDeg d inserts T_cur into SlotInv.
Once every degree < maxDeg + 1 has been cleared from SlotInv, slotTrees = [] and all
entries st.cons d (d ≤ n) are 0.
Root scattering (scatterBody_exec and scatterRootCode_exec) #
scatterRootCode inserts root T₀ (iterCur = T₀.root.val) into cons, linking equal-degree
roots and updating maxDegReg in t + 50 * slotTrees'.length ≤ 63 + 50 * slotTrees₀.length
instructions while preserving all registers < 33 and framing otherNodes.
Consolidation scatter loops (childScatterLoop and rootScatterLoop) #
Phase B slot gathering (gatherSlotsLoop_exec) #
extractMinCode correctness and O(log n) amortized bound #
extractMinCode implements .extractMin on FibInv within 410 * (Nat.log 2 n + 1)
amortized instructions (t + potential y ≤ 410 * (Nat.log 2 n + 1) + potential x).