We have been doing algorithm analysis in university, and after analyzing binary search algorithm, the following equation resulted. What we have to do now is to prove that $ \left \lfloor {\log n} \right \rfloor = \left \lfloor {\log \left \lceil \frac {n-1}{2}\right \rceil} \right \rfloor + 1$
This has been causing me some headache today and desperately I decided to put it on this forum in hope of some hint that my tunnel sight now may have missed.
At first, I tried to get a proof just by mathimatical transformations. That just didn´t go very well, although I got this $ \left \lfloor {\log n} \right \rfloor = \left \lfloor {\log (\left \lceil \frac {n}{2}\right \rceil*2-2)} \right \rfloor$ which I tried to prove seperately for n even and not even, but I got stuck.
My next approach was considering for n not even -> n-1 is even. And then
$2^k$ $\leq$ n-1 < n < $2^{k+1}$ $\Rightarrow$ $ k \leq log (n-1) < log n < k+1 $
Even though I made a better progress this way, I just can´t relate with the ceiling function inside the logarithm.
Can somebody give me a hint about that? Thanks in advance!
Your original statement is not true (please read the whole answer). But the following statement is correct:
$$\left \lfloor {\log_2 n} \right \rfloor = \left \lfloor {\log_2 \left \lceil \frac {n-1}{2}\right \rceil} \right \rfloor + 1\tag{1}$$
Proof:
Every number $n$ can be placed between two cosecutive powers of 2. In other words, there exists $k$ such that:
$$2^k\le n\le2^{k+1}-1\tag{1}$$
Obviously:
$$k\le\log_2n<k+1$$
$$k=\lfloor\log_2n\rfloor\tag{2}$$
On the other side from (1):
$$\frac{2^k-1}2 \le \frac{n-1}{2} \le \frac{2^{k+1}-2}2$$
$$2^{k-1}-\frac12 \le \frac{n-1}{2} \le 2^k-1$$
$$\lceil 2^{k-1}-\frac12\rceil \le \lceil\frac{n-1}{2}\rceil \le 2^k-1$$
$$2^{k-1} \le \lceil\frac{n-1}{2}\rceil \le 2^k-1$$
$${k-1} \le \log_2\lceil\frac{n-1}{2}\rceil \le \log_2 (2^k-1)<k$$
$${k-1} =\lfloor \log_2\lceil\frac{n-1}{2}\rceil \rfloor$$
$$k=\lfloor \log_2\lceil\frac{n-1}{2}\rceil \rfloor+1\tag{3}$$
By comparing (2) and (3) you get:
$$\lfloor\log_2n\rfloor = \lfloor \log_2\lceil\frac{n-1}{2}\rceil \rfloor+1$$
...which completes the proof.
You can easily prove that the original statement is not true. You are basically saying that the function:
$$f(n)=\left \lfloor {\log n} \right \rfloor - \left \lfloor {\log \left \lceil \frac {n-1}{2}\right \rceil} \right \rfloor - 1$$
...is equal to zero for all values of $n$.
This is not true if "$\log$" stands for logartihm with base 10:
This is also not true if "$\log$" stans for natural logarithm "$\ln$":
If you don't trust these plots, calculate the value for $n=45$ and in both cases the result is -1, not 0.