Sobes.tech
Junior

What is the time complexity of the quicksort algorithm?

sobes.tech AI

Answer from AI

Time complexity of the quicksort algorithm:

  • Average: O(n log n). Achieved when the pivot element is chosen such that it splits the array into two roughly equal parts.
  • Worst case: O(n^2). Occurs if the pivot element is constantly chosen as the smallest or largest, leading to a degenerate case where one of the subarrays is always empty.
  • Best case: O(n log n). Similar to the average case, with an optimal choice of the pivot element at each step.