?

Algorithms & Data Structures

Free Version

Upgrade subject to access all content

Difficult

Writing Recursive Functions that Terminate Correctly

ALGOR-LJDK3F

Which of the following recursive functions will terminate properly, assuming only positive inputs are allowed?

A
public static int countdownByTwo(int x) {
   if(x == 0)
      return 0;

   return x + countdownByTwo(x - 2);
}
B
public static int fibonacci(int x) {
   if(x == 0 || x == 1)
      return x;

   return fibonacci(x - 1) + fibonacci(x - 2);
}
C
public static int factorial(int x) {
   if(x == 0)
      return 1;

   return factorial(x) * factorial(x - 1);
}
D
public static int funky(int x) {
   return funky(x - 1);
}