Recursion

AP Computer Science A· difficulty 4/5

Sum of array recursively:

  • A

    sum(arr, n) = if (n == 0) return 0; else return arr[n-1] + sum(arr, n-1);

    check_circle
  • B

    Cannot recurse on arrays

  • C

    Sort first

  • D

    for-each only

Explanation

Base case empty (n=0); add arr[n-1] to sum of first n-1.

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

Related questions