A sorting algorithm is described as stable if equal elements are1. Insertion sort is stable.
in the same relative order in the sorted sequence as in the original sequence.
When A[j] is inserted into the already sorted sequence A[1],...A[j-1],2. Merge sort is stable if the merging procedure
only elements A[i]>A[j] are shifted right to make room for A[j].
Thus A[j] is never inserted before an A[i]<=A[j].