3. Remember that the selection sort makes n number of passes over the data (wher
ID: 3868351 • Letter: 3
Question
3. Remember that the selection sort makes n number of passes over the data (where n is the size of the
data), with each of the passes, looks for the largest value and, after completing the pass, places it in
the proper location. Write the elements of the array below after each of the first 3 passes of a
selection sort. (7 points)
int[] numbers = {22, 77, 44, 33, 88, 66, 11, 99, 55};
selectionSort(numbers);
Before the sort {22, 77, 44, 33, 88, 66, 11, 99, 55}
After the pass 1
After the pass 2
After the pass 3
Explanation / Answer
Before the sort {22, 77, 44, 33, 88, 66, 11, 99, 55}
99 is highest, and it should be swaped with item at position 8, and
After the pass 1 { 22, 77, 44, 33, 88, 66, 11, 55, 99}
now 88 is the highest( we ignore last item) and it should be swaped with item at position 6, and
After the pass 2 { 22, 77, 44, 33, 55, 66, 11, 88, 99}
now 77 is the highest( we ignore last two items) and it should be swaped with item at position 1, and
After the pass 3 { 22, 11, 44, 33, 55, 66, 77, 88, 99}
NOTE that after k passes we shall ignore last k items while searching for the highest element
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.