Permutation sorted by one bubble-sort sweep
Question
An array holds a uniformly random permutation of . Steven runs a single left-to-right pass of bubble sort on it (comparing each adjacent pair and swapping if out of order). What is the probability that the array is fully sorted afterwards?
Short answer
. A single pass produces the sorted array from exactly starting permutations: the pass is determined by which of its comparisons swap, and running each swap pattern backwards from the sorted array gives a distinct valid input. (Brute force for small confirms .)
Adapted from OpenQuant; question and answer rewritten by SelfMadeQuant.com.
See the hint and the full worked solution in the question bank (free account).
Open the worked solutionLessons behind this question
- Counting and Combinatorics
- Algorithms, Growth Rates, and Asymptotic Notation
- Quicksort and Randomized Quicksort
Start with a free lesson: Probability Fundamentals is part of a free topic. Create a free account, no card needed, to read it in full with worked solutions.
Read it free