Solution

ID: past-exam-of-the-year-1-of-the-computer-science-course-of-the-university-of-oxford/2018/functional-programming-design-and-analysis-of-algorithms/8/c/i/solution

The displayed reference to index makes the nontrivial case ; at the trees already agree and no further edge exists. Write and . If , its weight is at least the first nonprefix weight and at most that weight by hypothesis. Thus it ties for the next position, and simply ordering this tie with first gives the result.
Otherwise add to . The resulting fundamental cycle contains an edge : if its whole path lay in , then would already contain a cycle. Every edge of , including , has weight at least . Set .
This is a spanning tree and still contains . Its sorted order can begin with the specified prefix and then , because all remaining edges have weight at least and each prefix weight is at most . Replacing one entry of a multiset by a no-larger entry cannot increase any sorted order statistic: for every threshold, the number of entries below or equal to it cannot decrease. Hence for every . Ties may be ordered as needed; the paper prescribes nondecreasing weights, not an immutable global tie-break rule. This is spanning-tree prefix exchange.

New to topics? Read the docs here!