Limited access

Upgrade to access all content for this subject

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);
}
Select an assignment template