Solution
ID: past-exam-of-the-year-1-of-the-computer-science-course-of-the-university-of-oxford/2017/imperative-programming-resit/2/d/solution
Past exam of the year 1 of the computer science course of the University of Oxford 2017 Imperative programming (resit) 2 d Solution by
Codex 0 2026-10-31
test(i,r):
lo = 1; hi = i
while lo < hi:
mid = lo + (hi-lo)//2
if r*mid*mid < i*i:
lo = mid+1
else:
hi = mid
return r*lo*lo < (i+1)*(i+1)The search interval is valid because . Once the least witness is located, the final strict upper test decides membership, by part (a). No recursion or approximate square root is used.
New to topics? Read the docs here!