-
What does the following algorithm approximate?
(Assume m > 1, ∈ > 0).
x = m; y = 1; while (x– y > ∈ )
{ x = (x + y)/ 2;
y = m / x;
}
print (x);
-
- log m
- m2
- m1 / 2
- m1 / 3
- log m
Correct Option: C
Here we take let x = 16
Loop will stop when x – y = 0 or > 0
Iteration | X | Y |
1 | (16 + 1)/ 2 = 8 | 16/ 8 = 2 |
2 | (8 + 2)/ 2 = 5 | 16/ 5 = 3 |
3 | (5 + 3)/ 2 = 4 | 16/ 4 = 4 |
Here X = Y
Then take X which is 4.
(m)1 / 2 = 4 = (16)1 / 2
Hence (c) is correct option.