Given the sequence 9 2 3 8 7 4 5 6 List all the element comp
Given the sequence 9, 2, 3, 8, 7, 4, 5, 6 List all the element comparisons made by insertion sort in the corresponding order. Use to denote a comparison of a and b. If the algorithm compares A[i] with A[j], you should write , rather than . For example, if the algorithms compares the first element with the fourth element, you should write , rather than .
Solution
1. <9,2>
2 9 3 8 7 4 5 6
2. <9,3> <2,3>
2 3 9 8 7 4 5 6
3. <9,8> <8,3>
2 3 8 9 7 4 5 6
4. <9,7> <8,7> <3,7>
2 3 7 8 9 4 5 6
5. <9,4> <8,4> <7,4> <3,4>
2 3 4 7 8 9 5 6
6. <9,5> <8,5> <7,5> <4,5>
2 3 4 5 7 8 9 6
7. <9,6> <8,6> <7,6> <5,6>
2 3 4 5 6 7 8 9
Thanks, Let me know if there is any concern
