What is the time complexity of quicksort in the average case?

Practice Questions

Q1
What is the time complexity of quicksort in the average case?
  1. O(n)
  2. O(n log n)
  3. O(n^2)
  4. O(log n)

Questions & Step-by-Step Solutions

What is the time complexity of quicksort in the average case?
  • Step 1: Understand what quicksort is. Quicksort is a sorting algorithm that sorts an array or list by dividing it into smaller parts.
  • Step 2: Learn about the divide-and-conquer approach. This means quicksort divides the list into two smaller lists based on a 'pivot' element.
  • Step 3: Know that in the average case, quicksort divides the list into two roughly equal parts. This helps in balancing the work done.
  • Step 4: Realize that each division takes linear time, O(n), because you have to look at each element to place it in the correct part.
  • Step 5: Understand that the number of times you can divide the list is logarithmic, O(log n), because you keep halving the size of the list.
  • Step 6: Combine the two parts: Since you do O(n) work for each of the O(log n) divisions, you multiply them together.
  • Step 7: Conclude that the average-case time complexity of quicksort is O(n log n).
No concepts available.
Soulshift Feedback ×

On a scale of 0–10, how likely are you to recommend The Soulshift Academy?

Not likely Very likely