GATE / CS ARCHIVE

GATE CSE 2004 / QUESTION 42

Arithmetic-mean square-root iteration

Algorithms · Correctness, Invariants & Design · Full GATE CSE 2004 paper

GATE 2004, Q42 2 marks · MCQ
Report issue

Correctness, Invariants & Design

Question 42, GATE 2004: For real arithmetic, m>1 and ε>0, what does this algorithm approximate?
x=m; y=1;
while(x-y>ε) { x=(x+y)/2; y=m/x; }
print(x);
Options:
(A) log m
(B) m²
(C) m^(1/2)
(D) m^(1/3)
Tap to enlarge
Your answer
Answer & solution

Answer: C (no official key was published)

1. In real arithmetic xy=m initially and after each iteration. Thus x is an upper bound and y=m/x a lower bound for sqrt(m).

2. Updating x to (x+m/x)/2 preserves x≥sqrt(m) and decreases it unless equality holds; resetting y preserves the invariant. The limits agree at sqrt(m).

3. At termination y≤sqrt(m)≤x and x−y≤epsilon, giving absolute error at most epsilon. This is an algorithm question about iteration, not a request to solve an excluded calculus topic; integer division would invalidate the real-arithmetic interpretation.

4. Teaching check: After the update, x is the arithmetic mean of a pair whose product is m, so x≥sqrt(m) by AM–GM. Setting y=m/x gives y≤sqrt(m). Their shrinking gap supplies a direct error bound, not merely a guess based on numerical similarity.

Original paper, page 6