0
$\begingroup$

I have this problem:

Let ⌊n⌋ be the largest power of 2 less than or equal to n. Prove that 1 + 2 + 4 + 8 + ... +⌊n⌋=O(n)

The series can also be written as this (?): 1 + 2 + 4 + 8 + ... + $2^{ \log_2 n} $

Wouldn't that then make the series 1 + 2 + 4 + 8 + ... + n which is not O(n)? I can't wrap my head around this.

  • 0
    Series can be written as $1+2+\cdots+2^{\lfloor \log_2 n \rfloor}$2017-02-15
  • 0
    Use that $1+2+2^2+\ldots + 2^m = 2\cdot 2^m - 1$ which follows from summing a geometrical series.2017-02-15
  • 0
    So how does that help me @winther. Would it be 1 + 2 + 4 + 8 + ... + $2^{ \log_2 n} $ = 2 * $2^{\log_2 n} $ -1 which then becomes 2 * 2n - 1?2017-02-15
  • 0
    Exactly (small mistake: it becomes $2[n] -1$ not $2\cdot 2n -1$). Finally use that $[n] \leq n$.2017-02-15

0 Answers 0