sum an array recusively decomposing by n/2
Originally posted by: tikwanleap
sum an array recusively decomposing by n/2
😕😕 need more details. What does this mean?
Originally posted by: RichieZ
i don't see how you can do it unless you use more paramters, like start and end indicies
Originally posted by: Elemental007
Originally posted by: tikwanleap
sum an array recusively decomposing by n/2
😕😕 need more details. What does this mean?
The array is of length n
when you make the function call to itself, you must divide n by 2 when getting the summation, rather than doing it linearly, i.e., n-1
Originally posted by: tikwanleap
Originally posted by: Elemental007
Originally posted by: tikwanleap
sum an array recusively decomposing by n/2
😕😕 need more details. What does this mean?
The array is of length n
when you make the function call to itself, you must divide n by 2 when getting the summation, rather than doing it linearly, i.e., n-1
ok, so i'm guessing here...
does that mean the function sums n/2 elements of the array and passes the the other half of the array to itself in the next function call?
Originally posted by: yoda291
I think it means something like this.
You must create function as follows:
func(arr,n)
{
do something to func(arr,n/2)
}
Originally posted by: gopunk
so basically, in O(log n) time? or are we allowed to do more than constant work per recursive call?
Originally posted by: m0ti
umm...
int doStupidSum(int *array, int n) {
if (n <= 0)
return 0;
if (n == 1)
return array[0];
int split = n/2;
return doStupidSum(array, split) + doStupidSum(array + split, n - split);
}
and this really should be in the programming forum and not OT.