Probability of finding a power of 2

$\begingroup$

Imagine I have set of numbers $(0,n]$. The problem I have in mind is to find the probability that the number I pick (randomly), from this set, is a power of $2$.

So I thought that I could use simply calculate the ratio of number of desired terms to total numbers in the set. Lets say there's a number $k$ such that $k$ is a power of $2$ and $k\leq n$. So, there must be $\log_{2}{k}$ other powers of $2$ that are contained in the set. I've used this reasoning to say that the probability must therefore be: $$ P=\frac{\log_{2}{n}}{n}=\frac{\ln{n}}{n\ln{2}}$$ My question is: Is this result correct? I understand if this must only be an approximation, in which case does a more accurate expression exist?

EDIT:

There's an addition I think I should mention: I could re-define the probability in terms of the floor function as: $$ P=\frac{\left \lfloor{\log_{2}{n}}\right \rfloor}{n}$$ Is this correct?

$\endgroup$ 1

1 Answer

$\begingroup$

Almost correct.

Since $1$ is also a power of $2$, the probability is $\dfrac{\left\lfloor{\log_{2}{n}}\right\rfloor\color\red{+1}}{n}$

$\endgroup$

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like