Advertisements
Advertisements
Question
In the following list containing integers, sort the list using Insertion sort algorithm. Also show the status of the list after each iteration.
15 -5 20 -10 10
Short Answer
Advertisements
Solution
Initial list: [15, -5, 20, -10, 10]
| Iteration | Element inserted | Status of list |
|---|---|---|
| 1 | -5 | [-5, 15, 20, -10, 10] |
| 2 | 20 | [-5, 15, 20, -10, 10] |
| 3 | -10 | [-10, -5, 15, 20, 10] |
| 4 | 10 | [-10, -5, 10, 15, 20] |
Sorted list: [-10, -5, 10, 15, 20]
shaalaa.com
Is there an error in this question or solution?
