Question states : Consider set A = {1, 2, 3 ... n}, what's the probability that randomly selected integer from set A is a perfect square?
Thankfully accepting answers.
Question states : Consider set A = {1, 2, 3 ... n}, what's the probability that randomly selected integer from set A is a perfect square?
Thankfully accepting answers.
On
First, let's have a look at how we can find a pattern to get the number of perfect squares in the range $R = 1, 2, 3 ... n$:
Let $k$ be the number of perfect squares in $R$. We need to find $k$.
Difference between consecutive perfect squares is $1 + 2i$, where $i = 1, 2, 3 ... k-1$. Upon subtle observation, you can discover that any perfect square can be written by the following formula:
Perfect Square (PS) = $1+i+2*(1+2+3+ ... i)$, where $i = 1,2,3 ... k-1$
Last perfect square has to be less than or equal to $n$. Therefore, putting $k-1$ in 'PS,' and equating it with $n$, we get
$1+k-1+2*(1+2+3+ ... k-1) <= n$
$\Rightarrow 1+k-1+2*\frac{(k-1)*k}{2} <= n$
$\Rightarrow k+ k^{2} - k <= n$
$\Rightarrow k <= \sqrt{n}$
Since, $k$ has to be positive, I neglected the negative part.
Now, the probability of selecting a perfect square from $R$ = $\frac{\sqrt{n}}{n}$
Note: If you find anything ambiguous, then please let me know in the comments below.
Note: $$ \begin{array}{c|l} n & \text{# of perfect squares} \\ \hline 1 & 1 \\ 2 & 1 \\ 3 & 1 \\ 4 & 2 \\ 5 & 2 \\ \cdot & \cdot \\ 8 & 2 \\ 9 & 3 \\ 10 & 3 \\ \cdot & \cdot \\ 15 & 3 \\ 16 & 4 \\ \cdot & \cdot \\ n & [\sqrt{n}] \end{array} $$ where $[n]$ is the largest integer less than or equal to $n$.
Hence: $$P(perfect \ square)=\frac{\# \ of \ perfect \ squares}{n}=\frac{[\sqrt{n}]}{n}.$$ For example, if $n=8:$ $$P(perfect \ square) = \frac{[\sqrt{8}]}{8}=\frac{2}{8}=\frac{1}{4}.$$