Review of Python Basics — Question 53
Back to all questionsWhat will be the status of the following list after the First, Second and Third pass of the insertion sort method used for arranging the following elements in descending order?
28, 44, 97, 34, 50, 87
Note: Show the status of all the elements after each pass very clearly underlining the changes.
list = [28, 44, 97, 34, 50, 87]
First pass
[28, 44, 97, 34, 50, 87] → [44, 28, 97, 34, 50, 87] — it will swap since 28 < 44
Second pass
[44, 28, 97, 34, 50, 87] → [44, 97, 28, 34, 50, 87] — it will swap since 28 < 97
[44, 97, 28, 34, 50, 87] → [97, 44, 28, 34, 50, 87] — it will swap since 44 < 97
Third pass
[97, 44, 28, 34, 50, 87] → [97, 44, 34, 28, 50, 87] — it will swap since 28 < 34
[97, 44, 34, 28, 50, 87] → [97, 44, 34, 28, 50, 87] — no swapping as 44 > 34
[97, 44, 34, 28, 50, 87] → [97, 44, 34, 28, 50, 87] — no swapping as 97 > 44