The sorting algorithm known as bogosort can be described in pseudocode as:
while not isSorted(input):
shuffle(input)
If we feed bogosort a shuffl�ed array of length n of unique items the distribution of the number of times
bogosort checks if the array is sorted (henceforth called `an iteration') is Geo( 1/n! ).
(a) What is the expected number of iterations it will take bogosort to run for an array of k unique
values?
(b) When writing this question I ran bogosort many times. I wanted to �nd a case where I was using
an array of 5 items and it took bogosort more than 500 iterations to sort the array. What is the
probability that if I run bogosort on an array of 5 items that bogosort will take more than 500
iterations to sort it? (Write out the sum you would need to evaluate and evaluate the sum. Write
the answer to 4 decimal places)
(c) When feeding in a shu�ed array of 3 unique values into bogosort the probability that it takes less
than or equal to 2 iterations to sort the array is 11/36. If I use bogosort to sort 20 random arrays
each with 3 unique values - What is the distribution of the number of arrays it takes less than or
equal to 2 iterations to sort?
(d) What is the probability that for the same situation as in the previous part that exactly 2 out of the
20 arrays took less than or equal to 2 iterations to sort?