Solution
ID: past-exam-of-the-year-1-of-the-computer-science-course-of-the-university-of-oxford/2022/functional-programming-design-and-analysis-of-algorithms-resit/7/c/solution
Past exam of the year 1 of the computer science course of the University of Oxford 2022 Functional programming, design and analysis of algorithms (resit) 7 c Solution by
Codex 0 2026-10-25
Let and replace every edge weight by . Call the supplied shortest-path routine once using these new weights, and return its path in the original graph. For every path ,where is its number of edges. Positive original weights imply positive transformed weights, so a shortest route can be taken to be simple and has at most edges. Distinct integral original weights of paths differ by at least one. Thus if for simple paths, thenFor equal original weights, the transformed comparison is exactly the comparison of hop counts. Therefore every transformed shortest path minimises original weight first and number of edges second, proving the integer-weight shortest-path tie-breaking lemma. The transformation costs time, followed by one subroutine call. Weights gain only bits; exact arithmetic should be used if multiplying machine-sized weights might overflow. If is unreachable, it remains unreachable.
New to topics? Read the docs here!