Home » Programming & Data Structure » Programming and data structure miscellaneous » Question

Programming and data structure miscellaneous

Programming & Data Structure

  1. 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);
    1. log m
    2. m2
    3. m1 / 2
    4. m1 / 3
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.



Your comments will be displayed only after manual approval.