Proofs: Even-Shiloach tree
These are the human proofs of Even-Shiloach tree, at full length.
The levels of an Even-Shiloach tree are the capped distances from the source full
This proof shows: correctness.
Let be the current graph, with positive integer weights, and let and be as on the page. Write for the level, with allowed. An edge supports if it is present and .
We prove that the following invariants hold before and after every iteration of the loop of line L4, and at the start and end of every deletion.
- (A) , and for every .
- (B) For every present edge with and : .
- (C) For every with , no edge before in supports .
- (D) Every with that is not supported by the edge at is in the queue .
Initialization. Line L1 sets , so (A) holds. For a present edge with : if or , the right side of (B) is or larger than ; otherwise . So (B) holds. The pointer is set to the first supporting edge, which exists for a finite because the last edge of a shortest path supports it; so (C) holds and (D) holds with an empty queue.
A deletion (lines L2 and L3). Deleting an edge can only increase distances, so does not decrease and (A) still holds. (B) and (C) speak only about present edges or about edges that do not support, and a deleted edge supports nothing, so they still hold. The only vertex that may lose the support at its pointer is the head of the deleted edge, and line L3 puts it into , so (D) holds.
An iteration of the loop. Let be taken from . If or , nothing changes. Otherwise line L5 moves forward over edges that do not support , which keeps (C). If it stops at a supporting edge, leaves and (D) holds for .
Otherwise no edge of supports : the edges before the old pointer by (C), and the others by the scan. Together with (B), every present edge has , because levels and weights are integers. Line L6 sets to .
- (A) still holds for . Suppose before the raise, so is finite and . Let be the last edge of a shortest path to ; then , so , and by (A) for , . This contradicts the inequality above. So . If the new level exceeds , then , which means , and line L7 sets , still within (A).
- (B) holds for the edges into , by the inequality above. For an edge out of , raising only increases the right side of (B) for .
- (C) holds for , since the pointer is reset to the first edge (or became ). For a vertex , raising can only make an edge stop supporting , never start: if supported before, it does not after, and if it did not, then by (B), which stays true. So no edge before starts to support .
- (D): if is still finite, line L7 puts it back into . Line L8 puts every out-neighbor into , which covers every whose support at was an edge from . Every other vertex keeps the support it had.
Termination. Each raise increases a level, levels are bounded by before they become , and each queue entry that does not raise a vertex removes one entry. So the loop ends.
Theorem. After each deletion, for every vertex .
Proof. When the queue is empty, by (D) every finite is supported by the edge at , so and is finite. Following the supporting edges from backward visits vertices with strictly decreasing finite levels, so it ends, and it can only end at , the one finite vertex that needs no support. This gives a path from to of length , so . By (A), , and is finite, so , and equality holds. If , then by (A) as well. Line L9 returns .