Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How is this space complexity calculated in this series sum?

Can someone explain the following space complexity calculation to me?

Given a stream of numbers of size b bits, calculate the sum of these numbers.

If we have seen T numbers so far, the sum is at most T2^b and hence needs at most O(b+log T) space.

Now, T2^b must be an upper bound because a more accurate upper bound would be T(2^b - 1).

But how did they calculate that the space upper bound is O(b +logT)?

like image 823
jcm Avatar asked Jan 22 '16 05:01

jcm


1 Answers

With m bits, you can store numbers up to (about) 2m. So, working the other way, if you know the sum, you need to take a logarithm to get the number of bits (and hence the space complexity).

Here, log(T 2b) = b + log(T).

like image 155
Ami Tavory Avatar answered Oct 15 '22 22:10

Ami Tavory