What is the running time of quicksort (with the middle element of the input array used as the pivot) for: a. Sorted input (5 P.). b. Reverse-sorted input (5 P.). For each case, explain your reasoning.

Respuesta :

Time complexity: In the majority of situations, quicksort performs in order of nlogn. It takes n2 comparisons to sort the array if the list of elements is already sorted or almost sorted.

Quicksort takes O(n log n) time in expectation to sort an array of n unique elements, averaged across all n! permutations of n elements with the same probability. Therefore, using the Lomuto partition technique, this takes O(n2) time. We achieve the best situation, where each member of the array is equal, by applying the Hoare partition technique. O is the time complexity (n). When the array is sorted in reverse, the worst case scenario happens. Therefore, insertion sort's worst-case time complexity is O. (n2). Quick Sort has a total time complexity of O. (nLogn). In the worst scenario, it does O(n2) comparisons, however this is an uncommon occurrence. Quick Sort has a space complexity of O. (nLogn).

To learn more about array click the link below:

brainly.com/question/19570024

#SPJ4