ITPEC FE Morning October 2021 Question 9
ITPEC FE Morning October 2021 — Question 9 of 80
McCarthy 91 Function — compute the result of a nested recursive function.
The function is defined as:
- M(n) = n - 10 if n > 100
- M(n) = M(M(n + 11)) if n ≤ 100
Compute M(97):
- M(97) → M(M(108)) → M(98)
- M(98) → M(M(109)) → M(99)
- M(99) → M(M(110)) → M(100)
- M(100) → M(M(111)) → M(101)
- M(101) = 101 - 10 = 91
- Unwind: M(100) = 91, M(99) = 91, M(98) = 91, M(97) = 91
Why not others:
- (a) 81 — arithmetic error in recursion unwinding
- (b) 86 — arithmetic error in recursion unwinding
- (d) 96 — misapplying n - 10 directly without full recursion
Key rule: McCarthy 91 function returns 91 for all n ≤ 100. For n > 100, it returns n - 10.
AI-generated — may contain errors
The original exam layout is preserved in the image so diagrams, formulas, tables, and code remain accurate.
This question comes from an official ITPEC past paper. ITPEC Practice is an independent study tool and is not affiliated with ITPEC. See the official FE past-paper collection or Report an issue.