Why it is $O(n)$ running time when we separate problems on n/2 subproblems each recursive call (and we continue to work on one side)

34 Views Asked by At

So, I do not understand why it is $O(n)$ running time in the case when we have some $n$ elements and with each recursive call we separate our array by half and we continue working only on a one half (considering that each recursive call requires comparisons with each elements in a sub-array). Is it some sequence? How to express it in a mathematical way? I guess we can express this recurrence as $T(n) = T(n/2) + O(n)$

Thanks!

1

There are 1 best solutions below

2
On BEST ANSWER

Because it is a geometric series. $$ T (n) \leq \sum_{k=0}^\infty \frac {cn}{2^k} = 2cn \in O (n)$$