0

In one of the algorithm text book they have mentioned that the following inequality

$$ n \leq 8\lg n \quad\text{solves to}\quad n \leq 43 $$

I am not sure how to solve this and get the answer $43$. Your help much appreciated.

reference: https://www.slader.com/textbook/9780262033848-introduction-to-algorithms-3rd-edition/14/exercises/2/

achille hui
  • 122,701

2 Answers2

2

Welcome to the world of Lambert function !

The only explicit solution of $$n=8 \log_2(n)\implies n=\exp\left(-W_{-1}\left(-\frac {\log(2)}8\right)\right)\approx 43.56$$ where $W_{-1}(.)$ is the second branch of Lambert function.

If you cannot use it, just numerical methods such as Newton. In this case, you look for the zero of function $$f(n)=n-8 \log_2(n) \qquad f'(n)=1-\frac {\log(8)} {n \log(2)}$$ and $$n_{k+1}=n_k -\frac{f(n_k)}{f'(n_k)}$$ Start with $n_0=8$ to see the path to convergence. I suppose that $5$ or $6$ iterations could be enough.

Try it with Excel and show the results in the question.

  • Thank you! Can you please give an example of solving using Newton ? – deepakguna Oct 05 '19 at 14:07
  • Thanks again, as i didnt know lambert and newton function i have choosen other one as answer. But definitely this one will be a better thing for a person who knows lambert function. Thanks again ! – deepakguna Oct 06 '19 at 06:02
1

Starting from

$$n \le 8\lg n$$

divide both sides by $8$ to form

$$\frac n8 \le \lg n$$

then since $\lg n=\log_2 n$ is the binary logarithm with base $2$ we have that

$$2^{n/8}\le 2^{\lg n}=2^{\log_2 n}=n$$

which means that

$$2^{n/8}\le n$$

From here we could reason that $2^{n/8}$ will eventually get larger $n$ and could experiment with different multiples of $8$ to make the computation easier. We have that $40\gt 2^5$ and $48<2^6$ so that

$$n=40 \implies 2^5\le n$$ $$n=48 \implies 2^6\ge n$$

therefore we should look between $40$ and $48$. Testing out the remaining values

$$n=41 \implies 2^{41/8}\le n$$ $$n=42 \implies 2^{42/8}\le n$$ $$n=43 \implies 2^{43/8}\le n$$ $$n=44 \implies 2^{44/8}\ge n$$

we see that $2^{n/8}\le n$ when $n\le 43$. We also have that

$$n=1 \implies 2^{1/8}\ge n$$ $$n=2 \implies 2^{2/8}\le n$$

which means that $2^{n/8}\le n$ is satisfied when $2 \le n \le 43$. We can verify this result graphically

enter image description here

and could also use induction to prove that $2^{n/8}\le n$ when $2 \le n \le 43$ as shown here.

Axion004
  • 10,056