How to prove $ \lfloor\log{(n+1)} / 2 \rfloor+1 = \lfloor\log{(n+1)}\rfloor$

79 Views Asked by At

I was trying to prove the equation below using the floor definition but finally I have given up.

I have no idea how to prove it. Could anyone give me a hint how to start?

$ \lfloor\log{(n+1)} / 2 \rfloor+1 = \lfloor\log{(n+1)}\rfloor$

The equation is taken from a CLRS task $21.4.2$ under this link.

1

There are 1 best solutions below

0
On BEST ANSWER

Note that while it is common to use "$\log$" to mean the binary logarithm ($\log_2$) in computer science related subjects, in math it is often used to describe the decimal logarithm ($\log_{10}$). I'll be using ($\log_2$) to avoid any confusion.

The main property you need is that for each real $r$ and and each integer $z$ the following is true :

$$\lfloor r+z\rfloor = \lfloor r \rfloor + z$$

That can be proved using the definition and induction on (non-negative) $z$ and then some substitution to cover negative $z$ as well. Under the assumption that you are more invested in computer science than math, I'd suggest skipping that formal proof and try to convince yourself why it is true.

Using that formula (switching sides), we can set $r=\log_2\frac{n+1}2$ and $z=1$ and get

$$ \begin{eqnarray} \left\lfloor \log_2\frac{n+1}2 \right\rfloor + 1 & = & \left\lfloor \log_2\frac{n+1}2 + 1 \right\rfloor \\ & = &\left\lfloor \log_2\frac{n+1}2 + \log_2(2) \right\rfloor \\ & = &\left\lfloor \log_2\left(\frac{n+1}2\times 2\right) \right\rfloor \\ & = &\left\lfloor \log_2(n+1) \right\rfloor \end{eqnarray} $$