Which of the following is the worst-case time complexity of the merge-sort algorithm?

Which of the following is the worst-case time complexity of the merge-sort algorithm? Correct Answer Θ(n lg n)

The correct answer is option 1.

Concept:

Merge-sort algorithm:

Merge Sort is a Divide and Conquer algorithm. It divides the input array into two halves, calls itself for the two halves, and then merges the two sorted halves.

The merge() function is used for merging two halves. The merge(arr, l, m, r) is a key process that assumes that arr and arr are sorted and merges the two sorted sub-arrays into one.

Algorithm:

MergeSort(arr, l,  r)

If r > l

  • Find the middle point to divide the array into two halves: middle m = l+ (r-l)/2
  • Call mergeSort for first half: Call mergeSort(arr, l, m)
  • Call mergeSort for second half: Call mergeSort(arr, m+1, r)
  • Merge the two halves sorted in steps 2 and 3: Call merge(arr, l, m, r)

Time complexity:

Sorting arrays on different machines. Merge Sort is a recursive algorithm and time complexity can be expressed as following recurrence relation.

T(n) = 2T(n/2) + θ(n)

Worst case= Θ(n lg n)

Best case= Θ(n lg n)

Average case= Θ(n lg n)

Hence the correct answer is Θ(n lg n).

Bissoy MCQ

Related Questions

If for an algorithm time complexity is given by O(1) then the complexity of it is ____________
If for an algorithm time complexity is given by O(log2n) then complexity will be ___________
If for an algorithm time complexity is given by O(n2) then complexity will ___________
If for an algorithm time complexity is given by O((3⁄2)n) then complexity will be ___________