5

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)?

Ami Tavory
  • 74,578
  • 11
  • 141
  • 185
jcm
  • 5,499
  • 11
  • 49
  • 78

1 Answers1

7

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).

Ami Tavory
  • 74,578
  • 11
  • 141
  • 185