Jump Trading Interview Question

Run one iteration of bubble sort. What's the probability that the array is now sorted?

Interview Answers

Anonymous

May 23, 2022

2^(n-1) / n!

12

Anonymous

Mar 15, 2022

I don't think it's quite as simple as the other answer claims. While it is true that the largest element will always be sorted, if the largest element is not first in the original list, there will be sorting performed prior to reaching the largest element.

1

Anonymous

Jul 17, 2020

After one iteration, the largest or smallest element is sorted depending on whether we sort in ascending or descending order. This means there are (n-1)! possible arrangements. Of these, only 1 arrangement represents the sorted array. So the probability of the array being sorted is 1/(n-1)!

6