Get inspired by the success stories of our students in IIT JAM MS, ISI MStat, CMI MSc DS. Learn More

This problem is a beautiful and elegant probability based on an elementary problem on how to effectively choose the key to a lock. This gives a simulation environment to problem 6 of ISI MStat 2017 PSB.

Suppose you have a 4-digit combination lock, but you have forgotten the correct combination. Consider the following three strategies to find the correct one:

(i) Try the combinations consecutively from 0000 to 9999.

(ii) Try combinations using simple random sampling with replacement from the set of all possible combinations.

(iii) Try combinations using simple random sampling without replacement from the set of all possible combinations.

Assume that the true combination was chosen uniformly at random from all possible combinations. Determine the expected number of attempts needed to find the correct combination in all three cases.

This problem really intrigues me, which gives me the excitement to solve and solve it.

- Expectation
- Simple Random Sampling With and Without Replacement
- Discrete Uniform Distribution
- Geometric Distribution
- Smoothing of Expectation . When and have some relationship, this helps us to calculate the expectation.

~ Discrete Uniform

Suppose, observe that if you select the keys consecutively, then for the true key , you need attempts. **(*)**

denotes the number of attempts required = due to** (*)**

.

This is something no one does, but let's calculate this and see why we don't do this and why we need to remember the keys that don't work like SRSWOR, which is the next case.

~ Discrete Uniform

denotes the number of attempts required.

Let's say, we have observed , which is fixed and we will calculate .

Observe that ~ Geom(\frac{1}{10000}\), since, there are unlimited trials and success occurs if you pick up the right key , which has a probability of .

Therefore, . Hence,

```
#Simple Random Sampling with Replacement
NUM = 0
size = 1000 # we have taken 1000 for easier calculation
key = sample(size,1)
number = NULL
random = sample(size,1)
N = 1
for (k in 1:1000) {
number = NULL
for (j in 1:100)
{
while (random != key)
{
random = sample(size,1)
N = N + 1
}
number = c(number,N)
random = sample(size,1)
N = 1
}
NUM = c(NUM,mean(number))
}
mean(NUM)
980.899
hist(NUM)
#Note Replace = TRUE will not work, since, this is an open-ended program
```

Hence, this is validated by our simulation.

This is the sort of key selection, we usually do. Let's investigate it.

~ Discrete Uniform

denotes the number of attempts required.

Let's say, we have observed , which is fixed and we will calculate .

. Hence, .

```
#Simple Random Sampling without Replacement
average = NULL
number = NULL
size = 10000
key = sample(size,1)
for (j in 1:1000)
{
for (i in 1:100)
{
option = sample(size,size, replace = FALSE)
v = which(option == key)
number = c(number,v)
}
average = c(average,mean(number))
}
mean(average)
4996.567
hist(average, freq = FALSE)
```

Stay tuned!

Stay Blessed!

This problem is a beautiful and elegant probability based on an elementary problem on how to effectively choose the key to a lock. This gives a simulation environment to problem 6 of ISI MStat 2017 PSB.

Suppose you have a 4-digit combination lock, but you have forgotten the correct combination. Consider the following three strategies to find the correct one:

(i) Try the combinations consecutively from 0000 to 9999.

(ii) Try combinations using simple random sampling with replacement from the set of all possible combinations.

(iii) Try combinations using simple random sampling without replacement from the set of all possible combinations.

Assume that the true combination was chosen uniformly at random from all possible combinations. Determine the expected number of attempts needed to find the correct combination in all three cases.

This problem really intrigues me, which gives me the excitement to solve and solve it.

- Expectation
- Simple Random Sampling With and Without Replacement
- Discrete Uniform Distribution
- Geometric Distribution
- Smoothing of Expectation . When and have some relationship, this helps us to calculate the expectation.

~ Discrete Uniform

Suppose, observe that if you select the keys consecutively, then for the true key , you need attempts. **(*)**

denotes the number of attempts required = due to** (*)**

.

This is something no one does, but let's calculate this and see why we don't do this and why we need to remember the keys that don't work like SRSWOR, which is the next case.

~ Discrete Uniform

denotes the number of attempts required.

Let's say, we have observed , which is fixed and we will calculate .

Observe that ~ Geom(\frac{1}{10000}\), since, there are unlimited trials and success occurs if you pick up the right key , which has a probability of .

Therefore, . Hence,

```
#Simple Random Sampling with Replacement
NUM = 0
size = 1000 # we have taken 1000 for easier calculation
key = sample(size,1)
number = NULL
random = sample(size,1)
N = 1
for (k in 1:1000) {
number = NULL
for (j in 1:100)
{
while (random != key)
{
random = sample(size,1)
N = N + 1
}
number = c(number,N)
random = sample(size,1)
N = 1
}
NUM = c(NUM,mean(number))
}
mean(NUM)
980.899
hist(NUM)
#Note Replace = TRUE will not work, since, this is an open-ended program
```

Hence, this is validated by our simulation.

This is the sort of key selection, we usually do. Let's investigate it.

~ Discrete Uniform

denotes the number of attempts required.

Let's say, we have observed , which is fixed and we will calculate .

. Hence, .

```
#Simple Random Sampling without Replacement
average = NULL
number = NULL
size = 10000
key = sample(size,1)
for (j in 1:1000)
{
for (i in 1:100)
{
option = sample(size,size, replace = FALSE)
v = which(option == key)
number = c(number,v)
}
average = c(average,mean(number))
}
mean(average)
4996.567
hist(average, freq = FALSE)
```

Stay tuned!

Stay Blessed!

Cheenta is a knowledge partner of Aditya Birla Education Academy

Advanced Mathematical Science. Taught by olympians, researchers and true masters of the subject.

JOIN TRIALAcademic Programs

Free Resources

Why Cheenta?

the expected value in uniform should be 5000.

It is written that N= U +1. But after that , it is written E(N) = E( U ) ? Isn't should be "E(N) = E( U ) +1"?