+ 1

How many Iteration and Recursive calls does it take to calculate the sum of numbers in a list of size n?

Say you have a_list = [2,3,4,8,6]

25th Mar 2018, 7:33 PM
E_E Mopho
E_E Mopho - avatar
1 Odpowiedź
+ 2
One interation. Recursive func would be like this: def CalcSum(arr,sum,index) : if(index!=len(arr)): return CalcSum(arr,sum+arr[index],index+1) return sum A loop function would look like this. def CalcSum(arr): sum=0 for x in range(len(arr)): sum+=arr[x] return sum
25th Mar 2018, 7:51 PM
Tomer Sim
Tomer Sim - avatar