The GATE Grind

GATE Programming and Data Structures: Recursion – Previous Year Questions

28 GATE previous year questions on Recursion (Programming and Data Structures, Computer Science) with answers and explanations, from every paper.

28 questions worth 49 marks in all (7 1-mark, 21 2-mark). Asked between 2007 and 2026, so you can see how the topic has been tested over time.

  1. GATE 2007 CS Q42 (2 marks, Multiple choice) – What is f(5)?
  2. GATE 2008 CS Q61 (2 marks, Multiple choice) – Fill ?1, ?2 to print a newline-terminated input string in reverse order.
  3. GATE 2008 CS Q75 (2 marks, Multiple choice) – Consider the C functions (assume N>n): What values do f1(8), f2(8) return?
  4. GATE 2009 CS Q18 (1 mark, Multiple choice) – Consider the program below. What value is printed?
  5. GATE 2021 CS (CS2) Q33 (1 mark, Numerical answer) – Find SomeFunction(15,255).
  6. GATE 2021 CS (CS2) Q59 (2 marks, Numerical answer) – What does this program print?
  7. GATE 2015 CS (CS3) Q38 (2 marks, Multiple choice) – How many calls to get, including the initial and base-case calls, occur for get(6)?
  8. GATE 2015 CS (CS2) Q21 (1 mark, Multiple choice) – What does foo("ABCD EFGH") print?
  9. GATE 2015 CS (CS2) Q24 (1 mark, Numerical answer) – Find fun(5).
  10. GATE 2010 CS Q45 (2 marks, Multiple choice) – What does this C program print?
  11. GATE 2011 CS Q58 (2 marks, Multiple choice) – Find foo(345,10).
  12. GATE 2011 CS Q59 (2 marks, Multiple choice) – Find foo(513,2).
  13. GATE 2013 CS Q52 (2 marks, MTA) – p starts at five. Find f(p,p). The first parameter is passed by reference and the second by value.
  14. GATE 2012 CS Q26 (1 mark, Multiple choice) – Which recurrence gives optimal Towers of Hanoi time for n disks?
  15. GATE 2016 CS (CS2) Q47 (2 marks, Numerical answer) – What does this program print? max returns the larger argument.
  16. GATE 2014 CS (CS2) Q50 (2 marks, Numerical answer) – Consider: double f(double x) if (abs(x*x - 3) < 0.01) return x; else return f(x/2 + 1.5/x); Give q to two decimals such that f(q) returns q.
  17. GATE 2014 CS (CS2) Q52 (2 marks, Multiple choice) – Consider the C function: int f(int j) static int i = 50; int k; if (i == j) printf("something"); k = f(i); return 0; else return 0; Which is TRUE?
  18. GATE 2017 CS (CS1) Q45 (2 marks, Multiple choice) – Consider the following two functions. The output printed when `fun1(5)` is called is
  19. GATE 2017 CS (CS1) Q46 (2 marks, Multiple choice) – Consider the C functions `foo` and `bar` given below: Invocations of `foo(3)` and `bar(3)` will result in:
  20. GATE 2016 CS (CS1) Q45 (2 marks, Multiple choice) – What will be the output of the following C program?
  21. GATE 2018 CS Q31 (1 mark, Numerical answer) – Consider the following C program: The output of this program is .
  22. GATE 2018 CS Q55 (2 marks, Numerical answer) – Consider the following program written in pseudo-code. Assume that `x` and `y` are integers. The number of times that the `print` statement is…
  23. GATE 2019 CS Q36 (2 marks, Multiple choice) – Consider the following C function. Which one of the following will happen when the function `convert` is called with any positive integer n as…
  24. GATE 2026 CS (CS2) Q61 (2 marks, Numerical answer) – Consider the following ANSI C function. The maximum possible value that can be returned from this function is . (answer in integer) Note: Ignore…
  25. GATE 2026 CS (CS1) Q61 (2 marks, Numerical answer) – Consider the recursive functions represented by the following code segment: The smallest positive integer n for which `foo(n)` returns 5 is . (answer…
  26. GATE 2025 CS (CS1) Q61 (2 marks, Numerical answer) – The value printed by the given C program is . (Answer in integer)
  27. GATE 2024 CS (CS1) Q19 (1 mark, Multiple choice) – Consider the following C program: Assume that the input to the program from the command line is 1234 followed by a newline character. Which one of the…
  28. GATE 2020 CS Q56 (2 marks, Numerical answer) – Consider the following C functions. The return value of fun2(5) is .