Prepin
Log in

What are the time complexities of the Quick Sort and Merge Sort algorithms?

Approach / Explanation

This inquiry pertains to the time complexities of two particular sorting algorithms: Quick Sort and Merge Sort. Time complexity quantifies the duration an algorithm takes to execute on a computer, typically represented using Big O notation. When addressing algorithm-related questions, it is crucial to grasp common time complexity notations: O(1) : Constant time O(n) : Linear time O(log n) : Logarithmic time O(n log n) : Linearithmic time O(n²) : Quadratic time O(n³) : Cubic time O(2^n) : Exponential time In this context, you are specifically required to identify the time complexity of Quick Sort and Merge Sort. You should be aware of these complexities for three scenarios: best case, average case, and worst case. If no cases are indicated, it is safe to assume you are discussing the worst-case time complexity.

Suggested Answer

Quick Sort exhibits an average and best-case time complexity of O(n log n) . However, in the worst-case scenario, such as when the input array is either sorted or reverse sorted, the time complexity increases to O(n²) . Conversely, Merge Sort maintains a time complexity of O(n log n) across all scenarios—worst, average, and best—since it reliably divides the array into halves, sorts them, and then merges the results.

Alternative Answer

Quick Sort sorts in place, and its time complexity can vary. The average and best-case scenarios have a time complexity of O(n log n) , where 'n' represents the number of items being sorted. However, the worst-case scenario occurs when sorting an already sorted or reverse sorted array, leading to a time complexity of O(n²) . On the other hand, Merge Sort maintains a consistent time complexity of O(n log n) across all scenarios—worst, best, and average. This consistency arises because Merge Sort always divides the array into two halves, sorts each half, and then merges them back together.

Question Details

Difficulty & Category

Medium
coding

Product

For CandidatesFor RecruitersCompaniesBrowse JobsInterview QuestionsDeep ProfileSkill AssessmentOpportunity Matching
Prepin.ai

© 2026 Prepin LLC · Philadelphia, PA · All rights reserved.