All Exams Test series for 1 year @ ₹349 only
Question

What is the average case time complexity of merge sort?

The correct answer is
$O(n \log n)$

Question Type: Algorithm Analysis

Step-by-Step Solution:

Merge sort is a divide-and-conquer algorithm. It works by recursively dividing the input array into smaller subarrays until each subarray contains only one element (which is inherently sorted). Then, it repeatedly merges the subarrays to produce new sorted subarrays until there is only one sorted array remaining.

The time complexity of merge sort can be analyzed as follows:

  • Dividing the array: This step takes O(log n) time, as the array is repeatedly halved.
  • Merging the subarrays: In each merge operation, we compare and copy elements from two subarrays, which takes O(n) time for an array of size n.

Since the merging operation takes O(n) time and the dividing operation takes O(log n) time, the overall average-case time complexity of merge sort is the product of these two: O(n log n).

Why other options are incorrect:

  • O(n): This is the time complexity of linear algorithms, such as searching for an element in a sorted array. Merge sort is not a linear algorithm.
  • O(1): This represents constant time complexity, indicating that the algorithm's runtime is independent of the input size. Merge sort's runtime is clearly dependent on the input size.
  • O(n² log n): This complexity is much higher than O(n log n) and is typical of inefficient algorithms. Merge sort is known for its efficiency.

Core Logic/Pattern: Merge sort's average-case time complexity is determined by the logarithmic number of divisions (O(log n)) multiplied by the linear time complexity of merging (O(n)), resulting in O(n log n).

Correct Answer: \(O(n \log n)\)

Was this answer helpful?

Important Questions from Asymptotic Worst Case Time and Time Complexity

  1. Arrange the following in ascending order of their average case complexity.

    Selection-sort, Quick-sort, Linear search, Binary search

  2. Arrange the following algorithms from the most efficient to least efficient based on their time complexity. 

    A. Kruskal's Algorithm

     B. Breadth first search Algorithm 

    C. Bellman-Ford Algorithm

     D. Dijkstra's Algorithm 

    E. Edmonds-Karp Algorithm. 

    Choose the correct answer from the options given below:

  3. Which of the following is correct order of increasing time complexity of algorithms

     A. Tower of Hanoi with n disk. 

    B. Binary search given n sorted numbers. 

    C. Heap sort given n numbers at the worst case. 

    D. Addition of two n x n matrices. 

    Choose the correct answer from the options given below:

Need Expert Advice?

Start Your Preparation with Prepp Mobile App

Download the app from Google Play & App Store
Download the app from Google Play & App Store
Prepp Mobile App