Skip to content
Official PYQ · 2014

GATE CS 2014 Set 2 Q40 — Recursion

Explain with AI

Consider the following function.

double f(double x){
    if( abs(x*x - 3) < 0.01) 
        return x;
    else 
        return f(x/2 + 1.5/x);
} 

Give a value qq (to 22 decimals) such that f(q)f(q) will return qq:_____. 

View worked solution

Answer: 1.72 : 1.74

The given C function implements the Newton-Raphson method to find the square root of 33.

The base condition of the recursion is:

∣x2−3∣<0.01\lvert x^2 - 3 \rvert < 0.01

For f(q)f(q) to return qq directly without entering any further recursive steps, the base condition must be satisfied for x=qx = q. That is:

∣q2−3∣<0.01\lvert q^2 - 3 \rvert < 0.01

Solving this inequality:

−0.01<q2−3<0.01-0.01 < q^2 - 3 < 0.01

2.99<q2<3.012.99 < q^2 < 3.01

Taking the positive square root:

2.99<q<3.01\sqrt{2.99} < q < \sqrt{3.01}

1.7291<q<1.73491.7291 < q < 1.7349

Thus, the only value of qq rounded to 22 decimal places that satisfies this condition is 1.731.73 (or −1.73-1.73 if considering negative roots).

The official GATE answer key accepts any value in the range 1.721.72 to 1.741.74.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Recursion questions