A simple sorting technique that scans the sorted list, starting at the beginning, for the correct insertion point for each of the items from the unsorted list… Read more »
analysis
Complexity Analysis
In any cases, (worse case, best case or average case), to sort the list in ascending order the number of comparisons between elements is the same.
Worst Case [8 7 6 3 1]
Average Case [7 8 3 1 6]
Best Case [1 3 6 7 8]
All lists with 5 elements need 10 comparisons to sort
all the data.
In the example given, it can be seen that the number of comparison for worse case and best case is the same with 10 comparisons.
• The difference can be seen in the number of swapping elements. Worst case has maximum number of swapping: 10, while best case has no swapping since all data is already in the right position.
• For best case, starting with pass one, there is no exchange of data occur.
• From the example, it can be concluded that in any pass, if there is no exchange of data occur, the list is already sorted. The next pass shouldn't be continued and the sorting process