public static int moves(int n) {
if (n == 0) return 0;
return 2 * moves(n - 1) + 1;
}
// call: moves(3)Minimum moves for 3 disks?
- A
6
- Bcheck_circle
7
- C
9
- D
8
Explanation
Towers of Hanoi requires 2^n - 1 moves; for n=3, that's 7.
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(3)Minimum moves for 3 disks?
6
7
9
8
Explanation
Towers of Hanoi requires 2^n - 1 moves; for n=3, that's 7.
Want 10 more like this — adaptive to your weak spots?