Skip to content

Permutation sorted by one bubble-sort sweep

Question

An array holds a uniformly random permutation of 1,2,…,n1,2,\dots,n. 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

2n−1/n!2^{n-1}/n!. A single pass produces the sorted array from exactly 2n−12^{n-1} starting permutations: the pass is determined by which of its n−1n-1 comparisons swap, and running each swap pattern backwards from the sorted array gives a distinct valid input. (Brute force for small nn confirms 1,2,4,8,…1,2,4,8,\dots.)

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 solution

Lessons behind this question

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