Freezesort

You are given an array A = 8 , 3 , 2 , 4 , 5 , 6 , 7 , 1 , 9 , 10 , 11 , 12 , 13 A = 8 , 3 , 2 , 4 ,5 , 6 , 7 , 1 ,9,10,11,12,13 of size n n . As long as the array is not sorted, in each step, a subset of A A is randomly permuted. This subset is optimally chosen each time so that A A is sorted in the least amounts of steps. What is the expected value of the total number of times this operation needs to be done in order to sort A A ?


The answer is 4.

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

1 solution

Nicola Mignoni
Jul 12, 2019

Since the vector A = ( 8 , 3 , 2 , 4 , 5 , 6 , 7 , 1 , 9 , 10 , 11 , 12 , 13 ) A=(\underline{8},\underline{3},\underline{2},4,5,6,7,\underline{1},9,10,11,12,13) has only the underlined elements out of order, we just need to choose and permutate subsets {8,1} and {3,2}. For both of them, the probability of getting the right order follows a geometric distribution Geo ( p = 1 2 ) \text{Geo}\big(p=\frac{1}{2}\big) , so the expected number of steps to get one of them in order is E { 8 , 1 } = E { 3 , 2 } = 1 p = 2 E_{\{8,1\}}=E_{\{3,2\}}=\frac{1}{p}=2 . Evenutally, the expected number of steps to get the whole array sorted is E = E { 8 , 1 } + E { 3 , 2 } = 4 E= E_{\{8,1\}}+E_{\{3,2\}}=\boxed{4} .

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...