Pergunta de entrevista da empresa Jump Trading

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

Respostas da entrevista

Sigiloso

23 de mai. de 2022

2^(n-1) / n!

12

Sigiloso

15 de mar. de 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

Sigiloso

17 de jul. de 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