Given a sequence of n integers, A. To find the sum of the sequence we are following the following recursive algorithm, we make a new sequence B of size n/2 where B[i] = A[2*i] + A[2*i + 1] for i from 0 to n/2 - 1 and we replace A with B. When size of A is 1, we return the element itself.
Shouldn't the time complexity be calcualted as follows?
T(n) = T(n/2) + O(n/2)
or
T(n) = T(n/4) + O(n/4) + O(n/2)
or
T(n) = O(1) + O(2) + O(4) + ... + O(n/4) + O(n/2)
At this point I am not sure if I am doing it correctly and what this value should be equal to. I am assuming O(nlgn)
How do I arrive at the solution ? Also, using master theorem is giving me O(n), I am not sure if I am applying master theorem properly. Can someone please guide me here?