Computer Science
What 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.
Python Sorting
1 Like
Answer
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
Answered By
1 Like
Related Questions
Write a Python program to count number of items in a dictionary value that is a list.
Consider the following unsorted list:
105, 99, 10, 43, 62, 8.
Write the passes of bubble sort for sorting the list in ascending order till the 3rd iteration.Evaluate the following expression:
6 * 3 + 4 ** 2 // 5 - 8
Evaluate the following expression:
10 > 5 and 7 > 12 or not 18 > 3