What is the best-case time complexity of Quick Sort?
Practice Questions
Q1
What is the best-case time complexity of Quick Sort?
O(n)
O(n log n)
O(log n)
O(n^2)
Questions & Step-by-Step Solutions
What is the best-case time complexity of Quick Sort?
Step 1: Understand what Quick Sort is. It is a sorting algorithm that works by selecting a 'pivot' element from the array and partitioning the other elements into two groups: those less than the pivot and those greater than the pivot.
Step 2: Know that the efficiency of Quick Sort depends on how well the pivot divides the array. If the pivot divides the array into two equal halves, the algorithm performs best.
Step 3: In the best-case scenario, each time we pick a pivot, it splits the array into two equal parts. This means we will have log(n) levels of recursion, where n is the number of elements in the array.
Step 4: At each level of recursion, we have to process all n elements, leading to a total time complexity of O(n log n) in the best case.