One of the interesting features of Quicksort is that the number of key comparisons that are made is independent of the original order of the keys.
This means that the expected number of comparisons, the worst-case number of comparisons, etc., are all the exact same for a sorted input as for an unsorted input.
How many times are two elements compared in Quicksort?
- Now notice that as we have described Quicksort, no two elements will be compared twice.
- That's because one of the two elements being compared is always the current pivot.
- The first time two elements are compared, whichever one is the pivot is “used up” and doesnt appear in either of the subarrays.
How many number of comparisons are required to sort n equal keys using quick sort?
- We will count the number C(n) of comparisons performed by quicksort in sorting an array of size n.
- We have seen that partition() performs n comparisons (possibly n-1 or n+1, depending on the implementation).
- In fact, n-1 is the lower bound on the number of comparisons that any partitioning algorithm can perform.
Learn more about Quicksort
brainly.com/question/17018076
#SPJ4