Unit 10: Recursion
Showing 20 of 23 questions
What is the output of the following code?
What is the output of the following code?
What is the output of the following code?
What is the output of the following code?
How many total times is the method mystery called (including the initial call) when mystery(6) is invoked?
What is the output of the following code?
What is the output of the following code?
Which of the following is a necessary component of any recursive method?
What is the output of the following code?
What is returned by mystery(5)?
What is returned by mystery("abcd")?
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); }
What does this return for sum(5)?\npublic int sum(int n) { if (n == 0) return 0; return n + sum(n - 1); }
Binary search recursively halves the search space. What is the time complexity?
Which statement about recursion is true?
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); }
What does power(3, 4) return?\npublic int power(int base, int exp) { if (exp == 0) return 1; return base * power(base, exp - 1); }
Merge sort has a time complexity of:
A recursive method without a proper base case will most likely cause:
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