Which of the following is a stable sorting algorithm?Merge sort Typical in-place quick sortHeap sortSelection sort
Question
Which of the following is a stable sorting algorithm?
- Merge sort
- Typical in-place quick sort
- Heap sort
- Selection sort
Solution
Merge sort is a stable sorting algorithm.
Here's why:
-
Stable sorting algorithms maintain the relative order of records with equal keys (i.e., values). In other words, a sorting algorithm is stable if whenever there are two records R and S with the same key and with R appearing before S in the original list, R will always appear before S in the sorted list.
-
When merge sort is implemented properly, it ensures that the order of equal elements is maintained, thus making it a stable sort.
-
On the other hand, typical in-place quick sort, heap sort, and selection sort are not stable. They may change the relative order of records with equal keys. For example, in quick sort, the pivot element is moved to its final position in the sorted array with all smaller elements moved before it and all greater elements moved after it, which can change the relative order of equal keys.
Similar Questions
Which of the following is not a stable sorting algorithm?Insertion sort Selection sort Bubble sortMerge sort
Which of the following sorting algorithms is the fastest?OptionsQuick sortMerge sortInsertion sortShell sort
Which of the following is not in place sorting algorithm by default?ans.insertion sortmerge sortquick sortheap sort Previous Marked for Review Next
Merge sort uses which of the following technique to implement sorting? Options backtracking greedy algorithm divide and conquer dynamic programming
Which of the following sorting methods would be most suitable for sorting a list which is almost sorted?ans.selection sortmerge sortinsertion sortbubble sort
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.