Perform a selection sort on a list 20, 10, 8, 7, 6, 15, 21, 4.Follow the algorit
ID: 3613952 • Letter: P
Question
Perform a selection sort on a list 20, 10, 8, 7, 6, 15, 21, 4.Follow the algorithm given in the book (The last pass will be done. In all 8 passes.) Show all steps.Mention what swap is done after you find largest number from theunsorted list. Count number of in-place-swaps (swapping a numberwith itself). (The last pass will be done. In all 8 passes.) Show all steps.Mention what swap is done after you find largest number from theunsorted list. Count number of in-place-swaps (swapping a numberwith itself).Explanation / Answer
In-place swaps: [20, 10, 8, 7, 6, 15, 21, 4] [4, 10, 8, 7, 6, 15, 21, 20] [4, 6, 8, 7, 10, 15, 21, 20] [4, 6, 7, 8, 10, 15, 21, 20] ----here 8 is swapped withitself [4, 6, 7, 8, 10, 15, 21, 20] ----here 10 is swapped withitself [4, 6, 7, 8, 10, 15, 21, 20] ----here 15 is swapped withitself [4, 6, 7, 8, 10, 15, 21, 20] [4, 6, 7, 8, 10, 15, 20, 21] ----here 21 is swapped withitself Therefore in total there are 4 in-place swaps namely [for 8, 10,15,21]
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.