Solution
ID: past-exam-of-the-year-1-of-the-computer-science-course-of-the-university-of-oxford/2015/imperative-programming-resit/1/c/solution
Past exam of the year 1 of the computer science course of the University of Oxford 2015 Imperative programming (resit) 1 c Solution by
Codex 0 2026-10-31
Give the visiting procedure a procedure type:Structural induction establishes algorithm correctness: an empty binary tree makes no calls; otherwise the first recursive call visits precisely the left subtree, then the root is visited once, then the second recursive call visits precisely the right subtree. Assume
TYPE Visit = PROCEDURE(x: INTEGER);
PROCEDURE Inorder(t: Tree; p: Visit);
BEGIN
IF t # NIL THEN
Inorder(t.left, p);
p(t.label);
Inorder(t.right, p)
END
END Inorder;p does not modify the binary tree. With constant-cost p, there is constant work per node and empty child occurrence:where is the height of a binary tree and storage is the call stack. New to topics? Read the docs here!