GateAI
Recursion

GATE CSE 2014 Set 2 · Q40

NAT2 marksMedium

Time

Consider the following functiondouble 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 2 decimals) such that f(q)f (q) will return qq: _____.

Your answerNumerical answer

Enter a value to check

Solution

Step-by-step verified solution

Official answer: 1.73 (±0.01) (±0.01)

Recursion

The base condition checks whether ∣x2−3∣<0.01|x^2 - 3| < 0.01. If it is satisfied, the function returns xx directly without making any further recursive calls.

For f(q)f(q) to immediately return qq, the condition must hold for qq:

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

Notice that the recurrence update formula xn+1=xn2+1.5xn=12(xn+3xn)x_{n+1} = \frac{x_n}{2} + \frac{1.5}{x_n} = \frac{1}{2}\left(x_n + \frac{3}{x_n}\right) is the standard Newton-Raphson method for finding 3\sqrt{3}.

The exact fixed point is:

q=3≈1.732q = \sqrt{3} \approx 1.732

Checking q=1.73q = 1.73:

∣1.732−3∣=∣2.9929−3∣=0.0071<0.01|1.73^2 - 3| = |2.9929 - 3| = 0.0071 < 0.01

Thus, any value in the range 1.72 to 1.74 is valid.

Try the question first, then check your work.

Think the official key or this write-up is wrong?

Report error or challenge

Examiner trap

The misconception this question tests

This Recursion previous year question is Q40 of the GATE CSE 2014 Set 2 paper. Find more GATE CSE PYQs on Recursion in Programming and Data Structures, or browse all GATE CSE PYQs.

Free diagnostic

Where do you stand for GATE?

Take the 20-minute diagnostic: the 3 topics that cost you the most marks, and a rank range. Or sit 5 related Recursion PYQs now with no account.

One GATE CSE PYQ every morning

An official question by email at 7 AM IST, with a link to its verified solution. Unsubscribe in one click.

Recursion in GATE CSE

Recursion has 19 GATE CSE PYQs across 15 papers from 2011 to 2026. 5 of them are 2-mark NAT questions like this one, and GATE CSE 2014 Set 2 has 2.

How GATE tests Recursion

More from GATE CSE 2014 Set 2

Share this solution

A plain-text card for WhatsApp or Telegram study groups.

GateAI solution cardGATE CSE 2014 Set 2 · Q40 · NAT

Consider the following function double f(double x) { if ( abs(x*x - 3) Give a value q (to 2 decimals) such that f (q) will return q: …

Topic-wise GATE CS PYQs with verified steps

Independent practice explanation verified by the GateAI team. GATE is conducted by the IITs; question text follows the official paper.