Question: In this exercise we derive an estimate of the average-case complexity of the variant of the bubble sort algorithm that terminates once a pass has
a) Show that, under the assumption that the input is equally likely to be any of the n! permutations of these integers, the average number of comparisons used by the bubble sort equals E(X).
b) Use Example 5 in Section 3.3 to show that E(X) ≤ n(n − 1)/2.
c) Show that the sort makes at least one comparison for every inversion of two integers in the input.
d) Let I (P) be the random variable that equals the number of inversions in the permutation P. Show that E(X) ≥ E(I).
e) Let Ij,k be the random variable with Ij,k(P ) = 1 if ak precedes aj in P and Ij,k = 0 otherwise. Show that I (P) = Σk Σ j
h) Use parts (f) and (g) to show that E(I) =n(n − 1)/4.
i) Conclude from parts (b), (d), and (h) that the average number of comparisons used to sort n integers is Ɵ(n2).
Step by Step Solution
3.39 Rating (161 Votes )
There are 3 Steps involved in it
a Each of the n permutations occurs with probability 1n so clearly EX is the average number of compa... View full answer
Get step-by-step solutions from verified subject matter experts
Document Format (1 attachment)
923-M-C-M-S (2127).docx
120 KBs Word File
