Single-recursion van Emde Boas deletion #
This module defines and verifies key deletion on recursive minimum-excluded van Emde Boas trees ([Dem15], p. 5; [CLRS09], Section 20.3, p. 554).
At each internal depth d + 1:
- If the tree is empty or the query lies outside
[m, M], deletion returns immediately with no recursive call. - If
m = M(and hencex = m), the valid minimum-exclusion invariant guarantees that all clusters and the summary are already empty, so clearing the local header clears the node inO(1). - Otherwise (
m < Mandm ≤ x ≤ M), ifx = m, the smallest key stored in the clusters is located viasummary.minimumand(cluster i).minimuminO(1)header reads, promoted to becomenewMin, and targeted for deletion fromcluster i; ifx ≠ m,newMin = mis kept andx % universeSize dis targeted for deletion fromcluster (x / universeSize d). - Inspecting
(cluster i).boundsthen chooses at most one recursive deletion: whencluster iis a singleton{low},cluster iis cleared inO(1)viawithBounds noneanderaserecurses only onsummary; whencluster ihas distinct extrema (cm ≠ cM), at least one key remains after deletinglow, sosummarystays unchanged anderaserecurses only oncluster i. - Finally,
clusterMaxreconstructs the updated maximum inO(1)fromnewMin,s'.maximum, and the maximal occupied cluster's cachedmaximum.
These are mathematical correctness statements about the functional Lean representation, without a machine running-time claim.
Main definitions #
Tree.EraseTarget,Tree.eraseTarget: non-recursiveO(1)header selection of(newMin, i, low).Tree.clusterMax: non-recursiveO(1)reconstruction of a node's maximum from its summary and clusters.Tree.erase: single-recursion key deletion onTree d.
Main results #
Tree.erase_empty: deleting fromempty dreturnsempty d.Tree.valid_erase: deletion of any keyx : ℕpreservesTree.Valid.Tree.contains_erase:(t.erase x).Contains y ↔ y ≠ x ∧ t.Contains y.Tree.erase_eq_of_not_contains: deleting an absent key from a valid tree returnstunchanged.
References #
Header-selected cluster target for an internal-node deletion step (m < M and m ≤ x ≤ M).
- newMin : ℕ
Updated local minimum of the parent node.
- clusterIdx : Fin (universeSize d)
Index of the cluster from which
lowis to be removed. - low : ℕ
Low-order coordinate to remove from
cluster clusterIdx.
Non-recursive O(1) header helper selecting (newMin, clusterIdx, low) when m < M and
m ≤ x ≤ M ([Dem15], p. 5; [CLRS09], Section 20.3, p. 554).
Reconstruct a node's maximum in O(1) header reads from newMin, s.maximum, and the
maximal occupied cluster's cached maximum ([Dem15], p. 5; [CLRS09],
Section 20.3, p. 554).