Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stability of Merge sort [closed]

Is merge sort stable? I read it in a book which says merge sort is stable as long as the merge operation implemented properly. Is that true?

like image 974
Mr.Php Avatar asked Feb 23 '13 04:02

Mr.Php


People also ask

Does merge sort is stable?

Unlike some (efficient) implementations of quicksort, merge sort is a stable sort. Merge sort's most common implementation does not sort in place; therefore, the memory size of the input must be allocated for the sorted output to be stored in (see below for variations that need only n/2 extra spaces).

Is merge sort stable or unstable?

Several common sorting algorithms are stable by nature, such as Merge Sort, Timsort, Counting Sort, Insertion Sort, and Bubble Sort. Others such as Quicksort, Heapsort and Selection Sort are unstable. We can modify unstable sorting algorithms to be stable.

Why merge sort is called stable sort?

A sorting algorithm is said to be stable if two objects with equal keys appear in the same order in sorted output as they appear in the input unsorted array. Some Sorting Algorithm is stable by nature like Insertion Sort, Merge Sort and Bubble Sort etc.


1 Answers

true. It depends on how you properly implement the merge sort. http://en.wikipedia.org/wiki/Stable_sort#Stability

like image 136
NinjaV Avatar answered Oct 04 '22 02:10

NinjaV