Unit 10: Recursion

Showing 20 of 23 questions

Q1
MULTIPLE_CHOICEEasy

What is the output of the following code?

Q2
MULTIPLE_CHOICEMedium

What is the output of the following code?

Q3
MULTIPLE_CHOICEHard

What is the output of the following code?

Q4
MULTIPLE_CHOICEMedium

What is the output of the following code?

Q5
MULTIPLE_CHOICEHard

How many total times is the method mystery called (including the initial call) when mystery(6) is invoked?

Q6
MULTIPLE_CHOICEHard

What is the output of the following code?

Q7
MULTIPLE_CHOICEMedium

What is the output of the following code?

Q8
MULTIPLE_CHOICEEasy

Which of the following is a necessary component of any recursive method?

Q9
MULTIPLE_CHOICEHard

What is the output of the following code?

Q10
MULTIPLE_CHOICEMedium

What is returned by mystery(5)?

Q11
MULTIPLE_CHOICEHard

What is returned by mystery("abcd")?

Q12
MULTIPLE_CHOICEMedium

What does this method return when called with mystery(4)?\npublic int mystery(int n) { if (n <= 1) return 1; return n * mystery(n - 1); }

Q13
MULTIPLE_CHOICEMedium

What does this return for sum(5)?\npublic int sum(int n) { if (n == 0) return 0; return n + sum(n - 1); }

Q14
MULTIPLE_CHOICEHard

Binary search recursively halves the search space. What is the time complexity?

Q15
MULTIPLE_CHOICEMedium

Which statement about recursion is true?

Q16
MULTIPLE_CHOICEHard

What is the issue with this naive recursive Fibonacci implementation?\npublic int fib(int n) { if (n <= 1) return n; return fib(n-1) + fib(n-2); }

Q17
MULTIPLE_CHOICEMedium

What does power(3, 4) return?\npublic int power(int base, int exp) { if (exp == 0) return 1; return base * power(base, exp - 1); }

Q18
MULTIPLE_CHOICEHard

Merge sort has a time complexity of:

Q19
MULTIPLE_CHOICEMedium

A recursive method without a proper base case will most likely cause:

Q20
MULTIPLE_CHOICEHard

Consider the following recursive method. \npublic static int f(int n) { if (n <= 1) return n; return f(n - 1) + f(n - 2); } \nHow many times is f called (including the initial call) when evaluating f(5)?

Advertisement