Solution
ID: past-exam-of-the-year-1-of-the-computer-science-course-of-the-university-of-oxford/2015/imperative-programming-resit/3/c/solution
Past exam of the year 1 of the computer science course of the University of Oxford 2015 Imperative programming (resit) 3 c Solution by
Codex 0 2026-10-31
Treat the live array segment as a FIFO queue of runs. Remove its first two runs, append their merged result, and repeat:Compute both run boundaries before writing the destination, which starts at the old
PROCEDURE Sort(a, b: INTEGER; VAR c, d: INTEGER);
VAR x, y, z: INTEGER;
BEGIN
c := a; d := b;
WHILE c < d DO
x := Run(c, d);
IF x = d THEN RETURN END;
y := Run(x, d);
z := y-c;
Merge(c, x, y, d);
c := y;
d := d+z
END
END Sort;d. The untouched suffix is followed by the new merged run. The endpoints returned in c,d always describe the live sequence; obsolete values before c are ignored. As allowed, assume enough destination capacity. New to topics? Read the docs here!