GATE DA 2025 Set 1 — Question 63
Go beyond PYQs with Success TrackerAI-powered personalised practice and doubt support. Unlimited practice on eligible plans; AI usage limits apply.NAT+2 / -0MediumRecursionFunctions, File & Error HandlingProgramming, Data Structures & Algorithms
Programming, Data Structures & Algorithms → Functions, File & Error Handling → Recursion
Last updated
Question
Consider the following Python code snippet.The value printed by the code snippet is __________ (Answer in integer)
def f(a,b):
if (a==0):
return b
if (a%2==1):
return 2*f((a-1)/2,b)
return b+f(a-1,b)
print(f(15,10))
Correct answer
160 to 160
Solution
We trace the execution of
f(15, 10):1.
f(15, 10):-
a = 15(odd). - Returns
2 * f((15-1)/2, 10)=2 * f(7, 10).
f(7, 10):-
a = 7(odd). - Returns
2 * f((7-1)/2, 10)=2 * f(3, 10).
f(3, 10):-
a = 3(odd). - Returns
2 * f((3-1)/2, 10)=2 * f(1, 10).
f(1, 10):-
a = 1(odd). - Returns
2 * f((1-1)/2, 10)=2 * f(0, 10).
f(0, 10):-
a = 0. - Returns
b= 10.
-
f(0, 10) = 10 -
f(1, 10) = 2 * 10 = 20 -
f(3, 10) = 2 * 20 = 40 -
f(7, 10) = 2 * 40 = 80 -
f(15, 10) = 2 * 80 = 160
Continue learning with Success Tracker
A step still unclear? Work through it with support
Use Success Tracker to ask about the reasoning, then try another GATE DA question to check your understanding.
AI-powered practice· Unlimited practice on eligible plans
- PYQs with solutions
- Attempt available previous-year questions, then compare your reasoning with the worked solution. Coverage varies by stream.
- Practice that adapts
- Choose a topic, work on weaker areas and bookmark questions to revisit. Your attempts feed your progress tracking.
- AI doubt support
- Ask follow-up questions about a step or concept while practising, instead of stopping at the final answer.
Unlimited practice is available on eligible plans. Free practice and AI usage have limits; check the current plan allowances before choosing.
This page stays readable without an account. AI responses can be wrong; check them against the solution and source material.
Success Tracker stats
70%of attempts correct
2m 17smedian time
10 attempts
More questions on Functions, File & Error Handling
2026 Set 1 Q15Consider that the quick sort algorithm is used to sort an array of distinct randomly ordered…2026 Set 1 Q16Consider the given Python program. [code] Which of the following is the correct output of this…2026 Set 1 Q25You are given the following Pre-order and In-order traversals of a Binary Tree T with nodes E, F,…2026 Set 1 Q31Let A be a sorted array containing 1000 distinct integers. You perform a recursive binary search on…2026 Set 1 Q39A recursive function in Python is given. [code] Now, consider the following function call:…