Apologies! Let me put the details
Depth 3 is considered as the terminating condition because the tree on which we are implementing this algorithm has a depth of 3. NodeIndex * 2 + i will always be in range because here nodeindex is always zero and only i is incrementing to make nodeindex increase in value.
And sorry index error is initially on line 11.
So for example I put the following inputs :
x = 8 (number of leaf nodes)
scr = { 3, 5, 6, 9, 1, 2, 0, -1 };
1st iteration :
nodeindex=0 , depth = 0, values:[-1]
2nd iteration :
nodeindex=0 , depth = 1, values:[-1]
3rd iteration :
nodeindex=0 , depth = 2, values:[-1]
4th iteration:
nodeindex=0 , depth = 3, values:[-1]
Line 11 runs: return values[nodeIndex]
Value returned to line 20 and finally to line 60.
After this, I see the index error(list out of range) at line 11.
Depth 3 is considered as the terminating condition because the tree on which we are implementing this algorithm has a depth of 3. NodeIndex * 2 + i will always be in range because here nodeindex is always zero and only i is incrementing to make nodeindex increase in value.
And sorry index error is initially on line 11.
So for example I put the following inputs :
x = 8 (number of leaf nodes)
scr = { 3, 5, 6, 9, 1, 2, 0, -1 };
1st iteration :
nodeindex=0 , depth = 0, values:[-1]
2nd iteration :
nodeindex=0 , depth = 1, values:[-1]
3rd iteration :
nodeindex=0 , depth = 2, values:[-1]
4th iteration:
nodeindex=0 , depth = 3, values:[-1]
Line 11 runs: return values[nodeIndex]
Value returned to line 20 and finally to line 60.
After this, I see the index error(list out of range) at line 11.