Proofs: Burstsort
These are the human proofs of Burstsort, at full length.
Burstsort sorts strings in lexicographic order full
This proof shows: correctness, termination.
Let for and otherwise. Give each node of the trie a label: the root has the empty label, and the child in slot of a node with label at depth has the label followed by the character . (Slot 0 never holds a node, because line L6 never bursts it.)
Invariant (I). At each moment, every string that has been inserted is in exactly one bucket. If that bucket is in slot of a node with label at depth , then has as a prefix and .
Proof. Insertion (lines L3 to L5): the walk of line L4 moves from a node with label at depth to the child in slot only if that slot holds a node, and that slot is not 0, so has the child label as a prefix. The walk stops at a node with label such that has prefix and slot does not hold a node; line L5 puts in that slot. Burst: BURST is called only with . The strings of that bucket have prefix and character at index , so they have the label of the new node as a prefix, and each one goes to slot of . Other buckets do not change.
Termination. Each string is inserted once. The walk of line L4 goes down one level per step, and a node at depth has a label of length that is a prefix of the string, so the walk takes at most steps. A burst moves the strings of one bucket one level down; a string in a bucket at depth in a slot has length more than , so a string can move down at most times in total. So the number of moves is finite, each burst moves at least one string, and the insertion phase ends. The traversal visits a finite trie, so the whole algorithm ends.
Order of the buckets. Let be in a bucket and in a bucket , and let the traversal of line L8 visit before . We show . Let be the deepest node that is on the path from the root to both buckets, with label at depth . Both strings have the prefix by (I). The buckets are reached from through different slots , because the traversal visits the slots of in increasing order and visits everything under slot before slot . Each string has equal to the slot it was reached through, by (I) when the bucket is in a slot of , and by the label of the child otherwise. So , and since and agree on their first characters, (Fact 1 of MSD radix sort).
Inside a bucket. If is in slot 0 of a node with label , all its strings equal by (I). If is in slot of a node at depth , all its strings agree on the first characters. For such strings, the lexicographic order is the order of the suffixes from index , so line L9 puts in order.
Result. Line L10 writes the buckets in the order of the traversal, each one sorted. By the two paragraphs above, the output is in lexicographic order, and by (I) every input string is written exactly once.