Recursive Searching and Sorting (Binary Search, Merge Sort)

AP Computer Science A· difficulty 4/5

f(4) → f(3) → f(2) → f(1) → f(0) returns 0 ← returns 1 ← returns 3 (= 2 + 1)

The diagram shows <code>f(n)</code> computing

  • A

    Sum of n down to 0

    check_circle
  • B

    n * f(n-1)

  • C

    Constant 0

  • D

    f(n+1)

Explanation

Each call returns its n + result of f(n-1); base f(0)=0 → cumulative sum.

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

Related questions