Draw the recursion trace for the execution of function BinarySum

Question:

Draw the recursion trace for the execution of function BinarySum(A, 2, 4) on array A = {1,2,3,4,5,6,7}.

Algorithm BinarySum(A, i, n)

Input: An array A and integers i and n

Output: The sum of the n integers in A starting at index i
if n = 1 then
return A[i]
return BinarySum(A, i, n/2) + BinarySum(A, i + n/2, n/2)
end if

Answer:

Leave a Comment

Your email address will not be published. Required fields are marked *