Calculate the Depth of the recursive algorithm

  • Thread starter Thread starter tsgiannis
  • Start date Start date
  • Tags Tags
    Algorithm Depth
AI Thread Summary
The discussion centers on determining the depth of recursion for a specific algorithm that sums elements of an array. The algorithm divides the array into halves, leading to a recursive structure that can be analyzed for depth. Participants suggest running the algorithm manually for small values of n, such as 1, 2, and 4, to identify a pattern. This pattern can then be used to derive a general rule for calculating recursion depth. The main focus is on finding resources or methods to better understand the recursive process rather than seeking a direct solution.
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.
 
Back
Top