Choosing the correct password on the $n-$th try

conditional probabilityprobability

I'm current working on the following probability problem:

A new secretary has been given $n$ computer passwords, only one of which will permit access
to a computer file. Because the secretary has no idea which password is correct, he chooses
one of the passwords at random and tries it. If the password is incorrect, he discards it and
randomly selects another password from among those remaining, proceeding in this manner
until he finds the correct password.

and

A security system has been set up so that if three incorrect passwords are tried before
the correct one, the computer file is locked and access to it denied. If $n = 7$, what is the
probability that the secretary will gain access to the file?

One can work this out rather easily via intuition.
$$
\begin{align}
\text{P(Correct password on first try)}=&\ \frac{1}{n}\\
\text{P(Correct password on second try)}=&\ \text{P(wrong first try)}\cdot\text{P(correct second try)}\\
=&\ \frac{n-1}{n}\cdot\frac{1}{n-1}\\
=&\ \frac{1}{n}\\
\text{P(Correct password on third try)}=&\ \text{P(wrong first try)}\cdot\text{P(wrong second try)}\cdot\text{P(correct third try)}\\
=&\ \frac{n-1}{n}\cdot\frac{n-2}{n-1}\cdot\frac{1}{n-2}\\
=&\ \frac{1}{n}
\end{align}
$$

Therefore the probability of getting access is $3\cdot\frac{1}{7}=\frac{3}{7}$.

My question is how can I formulate this rigorously? Particularly the conditional probability of the $i$-th attempt? Here's my attempt, but I find it rather clunky.

Denote $E$ as the event where the secretary gains access, $A_n$ as the event where the previous $(n-1)$ passwords picked were incorrect, and the $n-$th password was correct, and $k$ as the maximum attempts allowed. Thus
$$E=\bigcup^k_{i=1}A_i$$
Since each $A_{i}$ and $A_j$ is pairwise mutually exclusive,
$$P(E)=\sum^k_{i=1}P(A_i)$$
by one of the Kolmogorov axioms. Furtheremore, defining $T_i$ as the event where the $i$-th password picked is wrong, then

$$A_i=T_1\cap T_2\cap \ldots \cap T_{i-1} \cap \overline{T_i}$$
and for each $T$,
$$P(T_i)= \frac{n-i}{n -i+1}$$
and
$$P(\overline{T_i})=\frac{1}{n-i+1}$$
since each incorrect password is tossed out after the attempt. Finally,

$$A_i=\left(\frac{1}{n-i+1}\right)\cdot\prod^i_{j=1}\frac{n-i}{n -i+1}=\frac{1}{n}$$
which implies that
$$P(E)=\sum^k_{i=1}\frac{1}{n}=\frac{k}{n}$$

Relevant: Probability of guessing correct password (out of n) on k-th try when trying them at random

Best Answer

Assume $n$ passwords, and that security lock-out after $k$ failures: $k \in \{1,2,3,\cdots, (n-1)\}.$

Assume sampling done without replacement.

Line up the $n$ passwords in a row, in the order that they will be tried, and label them $P_1, P_2, \cdots, P_n$. Access attempt succeeds if and only if the correct password in $\{P_1, \cdots, P_k\}.$

Thus, probability is $\frac{k}{n}.$