Describe the concept of stable sorting algorithms and provide an example.

  • Bubble Sort
  • Heap Sort
  • Merge Sort
  • Quick Sort
Stable sorting algorithms maintain the relative order of equal elements in the sorted output as they were in the original input. Merge Sort is an example of a stable sorting algorithm because it preserves the order of equal elements during the merge phase. Quick Sort, Heap Sort, and Bubble Sort are not inherently stable unless additional steps are taken to maintain stability, such as using indexes or comparing indices during sorting. Understanding stable sorting is crucial in scenarios where maintaining the original order of equal elements is necessary.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *