What is the time complexity of merge sort?

Practice Questions

Q1
What is the time complexity of merge sort?
  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 merge sort?
  • Step 1: Understand that merge sort is a sorting algorithm that works by dividing an array into smaller parts.
  • Step 2: Realize that the array is divided in half repeatedly until each part has one element.
  • Step 3: Know that merging these parts back together involves comparing elements and sorting them.
  • Step 4: Recognize that the division of the array takes log(n) time because you keep halving it.
  • Step 5: Understand that merging the sorted parts takes linear time, which is O(n).
  • Step 6: Combine the two parts: the time complexity for merge sort is O(n) for merging and O(log n) for dividing.
  • Step 7: Conclude that the overall time complexity of merge sort 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