We generate permutation of given array randomly until we get it sorted.
It's expected complexity should be factorial n for n sized array, but I saw on google it's factorial n+1.
Can anyone explain to me how is it factorial n+1, because for a binomial distribution E(x) = 1/p(x).
Please purify my understanding.
Also is there any sorting algorithm better than bogosort ?
!n is the expected number of shuffles required to get to the sorted array, but after each shuffle you also need to check if it's sorted or not and that is why there should be an extra factor of n in the overall time complexity making it !(n+1).
it should be !n*n not !n+1