Let $n$ denote a positive integer. Suppose a function $F$ is defined as
$f(n)=
\begin{cases}
0, & n=1 \
f\left(\left\lfloor \frac{n}{2} \right\rfloor\right)+1, & n>1
\end{cases}$
What is $f(25)$? and what does this function find?
Given,
$f(1)=0$
Now find $f(25)$:
$f(25)=f\left(\left\lfloor \frac{25}{2} \right\rfloor\right)+1$
$f(25)=f(12)+1$
$f(12)=f(6)+1$
$f(6)=f(3)+1$
$f(3)=f(1)+1$
$f(1)=0$
Now putting values back:
$f(3)=0+1=1$
$f(6)=1+1=2$
$f(12)=2+1=3$
$f(25)=3+1=4$
So,
$f(25)=4$
This function counts how many times $n$ can be divided by $2$ until it becomes $1$.
So, it finds:
$\left\lfloor \log_2 n \right\rfloor$
Online Test Series, Information About Examination,
Syllabus, Notification
and More.
Online Test Series, Information About Examination,
Syllabus, Notification
and More.