118k views
0 votes
Insertion Sort (as the code is written in this module) is a stable sorting algorithm. Recall that a stable sorting algorithm maintains the relative order of records with equal keys.

1 Answer

5 votes

Final answer:

Insertion Sort is a stable sorting algorithm that preserves the relative order of records with equal keys.

Step-by-step explanation:

Insertion Sort is a stable sorting algorithm, which means it maintains the relative order of records with equal keys. This means that if two elements have the same value, their order in the original array will be preserved after the sort.

An example of a stable sort algorithm is when sorting a list of students based on their grades. If two students have the same grade, the one who appeared first in the original list will still be positioned before the other student after the sort.

In contrast, an unstable sort algorithm might change the relative order of equal keys. So, if we sorted the list of students based on their names using an unstable sort algorithm, two students with the same grade may end up being positioned differently in the sorted list based on their names.

User Xuri
by
8.3k points