1.

What is merge sort? What is the Time & Space Complexity for merge sort?

Answer»

Merge Sort is a Divide & Conquer algorithm that is used to sort a given INPUT (can be an ARRAY or linked list). It involved dividing the input into 2 halves at each step until input has only 1 element and then merging these sorted halves to finally get a sorted input.

Merge sort is not an in-place algorithm (which means you NEED to use extra SPACE for sorting the input). 
Merge sort is a stable algorithm which means if there are 2 same elements in the input, the sorted output will maintain the relative ordering of these elements.

  • Time Complexity: O(NLogN) even in the WORST case. (where N is the size of the input)
  • Space Complexity: O(N)


Discussion

No Comment Found