Calculate the Depth of the recursive algorithm

  • Thread starter Thread starter tsgiannis
  • Start date Start date
  • Tags Tags
    Algorithm Depth
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
1 reply · 3K views
tsgiannis
Messages
1
Reaction score
0

Homework Statement


Hello to everybody
I have this homework and my main issue is that is cannot find any bibliography to read that does what my homework requires.
The problem goes like
We have this recursive algorithm that calculates the sum of an array elements from array element k to array element n

procedure sum(A, left, right)
if left ? right then
if left = right then return(A
);
else return(0);
mid := [(left + right) / 2];
x := sum(A, left, mid);
y := sum(A, mid+1, right);
return(x + y);
The problem goes like this
If the array A has n elements that are an expression of 2 (like 8 = 2^3) find the depth of recursion for the call of the procedre sum(A,1,n)

I don't ask for the solution but just a helping hand to find some relative material.

Homework Equations





The Attempt at a Solution

 
Physics news on Phys.org
I've never seen that language before, so I don't know what is going on in your code at all. If I were you, I'd probably run through the algorithm by hand for n = 1, 2, 4 and by then, a pattern will probably develop. Then, use that pattern to derive the general rule for depth.