Recursion

AP Computer Science A· difficulty 3/5

public static int moves(int n) {
  if (n == 0) return 0;
  return 2 * moves(n - 1) + 1;
}
// call: moves(5)

Minimum moves for 5 disks?

  • A

    31

    check_circle
  • B

    16

  • C

    32

  • D

    25

Explanation

2^5 - 1 = 31 moves.

Want 10 more like this — adaptive to your weak spots?

Related questions