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
GATE CSE 2014 Set 2 · Q40
Time
double f(double x) {
if ( abs(x*x - 3) < 0.01) return x;
else return f(x/2 + 1.5/x);
}Give a value (to 2 decimals) such that will return : _____.Your answerNumerical answer
Solution
Official answer: 1.73 (±0.01) (±0.01)
RecursionThe base condition checks whether . If it is satisfied, the function returns directly without making any further recursive calls.
For to immediately return , the condition must hold for :
Notice that the recurrence update formula is the standard Newton-Raphson method for finding .
The exact fixed point is:
Checking :
Thus, any value in the range 1.72 to 1.74 is valid.
Try the question first, then check your work.
Examiner trap
Find a fixed point of the recurrence relation or a value of for which the base condition holds true directly.
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
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.
An official question by email at 7 AM IST, with a link to its verified solution. Unsubscribe in one click.
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 RecursionIndependent practice explanation verified by the GateAI team. GATE is conducted by the IITs; question text follows the official paper.