
Patrick B. answered 07/11/20
Math and computer tutor/teacher
Array A:
pass 1: nothing changes
pass 2: 3 4 5 1 2 ---> 1 change
pass 3: 1 3 4 5 2 ---> 3 changes
pass 4: 1 2 3 4 5 ---> 3 changes
TOTAL: 7 changes
Array B:
pass 1: 1 5 2 3 4 ---> 1 change
pass 2: 1 2 5 3 4 ---> 1 change
pass 3: 1 2 3 5 4 ----> 1 change
pass 4: 1 3 3 4 5 ----> 1 change
TOTAL : 4 changes
Array C:
pass 1: 3 4 2 1 5 ---> 1 change
pass 2: 2 3 4 1 5 ---> 2 changes
pass 3: 1 2 3 4 5 ---> 3 changes
TOTAL : 6 changes
Array D:
pass 1: nothing changes
pass 2: 1 4 5 2 3 ---> 2 changes
pass 3: 1 2 4 5 3 ---> 2 changes
pass 4: 1 2 3 4 5 ---> 3 changes
TOTAL: 6 changes
Array E:
pass 1: nothing changes
pass 2: 1 4 5 3 2 --> 1 change
pass 3: 1 3 4 5 2 --> 2 changes
pass 4: 1 2 3 4 5 ---> 3 changes
TOTAL: 6 changes
Notice that Array B is almost sorted. That is why insertion sort is SO FAST when the array is almost sorted

Patrick B.
Denada and you're welcome. Quick sort is faster for random input. Insertion sort is faster for arrays that are ALMOST sorted.07/12/20
Sara P.
Thank you so much!07/12/20