retagged by
455 views
0 votes
0 votes
Consider performing QuickSort on an array of n distinct elements. What is the probability that no comparisons will be made between the smallest and largest element?

a. 1/n

b. 1/(n-1)

c. 2/n

d. 2/(n-1)

Answer: d. 2/(n-1)
retagged by

1 Answer

0 votes
0 votes
Total possibility of selecting pivot from array length n = n-1

No of Conditions where largest and smallest no is pivot = 2

( Until and unless maximum number and minimum number are pivots they can not be compared with each other)

Therefore,

Probability of not having comparison between smallest and largest number = 2/(n-1)

Related questions

0 votes
0 votes
2 answers
2
dhruba asked Jun 5, 2023
1,167 views
Binary search is performed on a sorted array of n elements. The search key is not in the array and falls between the elements at positions m and m+1 (where 1 ≤ m < n). ...
1 votes
1 votes
0 answers
3
Sahil Gupta asked Nov 25, 2014
775 views
Answer the following part:a) Show that, under the assumption that the input is equally likely to be any of the n! permutations of theseintegers, the average number of com...