Google News
logo
Algorithm - Interview Questions
Describe the merge sort algorithm.
Merge sort (also known as mergesort) is a general-purpose, comparison-based sorting algorithm developed in computer science. The majority of its implementations result in a stable sort, which indicates that the order of equal elements in the input and output is the same. In 1945, John von Neumann devised the merge sort method, which is a divide and conquer algorithm. The following is how a merge sort works conceptually:
 
* Separate the unsorted list into n sublists, each with one element (a list of one element is considered sorted).
* Merge sublists repeatedly to create new sorted sublists until only one sublist remains. The sorted list will be displayed then.
 
The time complexity of the Merge Sort Algorithm is O(nlog(n)) where n is the size of the list of the elements to be sorted while the space complexity of the Merge Sort Algorithm is O(n), that is, linear space complexity.
Advertisement