How is this answer t1=t2 wrong, because everytime the comparison would be made assuming last index to be pivot element, and that would be same for the two arrays of same size ? Please explain the correct part
Quiz on Sorting q5
Please mention the question here too.
Let P be a Quicksort Program to sort numbers in ascending order using the first element as pivot. Let t1 and t2 be the number of comparisons made by P for the inputs {1, 2, 3, 4, 5} and {4, 1, 5, 3, 2} respectively. Which one of the following holds?
t1 = t2
t1 > t2
t1 < t2
When first element or last element is chosen as pivot, Quick Sort‘s worst case occurs for the sorted arrays.
In every step of quick sort, numbers are divided as per the following recurrence.
T(n) = T(n-1) + O(n)
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.