Exercises 28—35 refer to selection sort, which is another algorithm to arrange the items in an array in ascending order.
Algorithm 11.3.2 Selection Sort
(Given an array , this algorithm selects the smallest element and places it in the first position. then selects the second smallest element and places it in the second position, and so forth, until the entire array is sorted. In general, for each to , the kth step of the algorithm selects the index of the array item will, minimum value from among . Once this index is found, the value of the corresponding array item is interchanged with the value of unless the index already equals k. At the end of execution the array elements are in order.] Input: n [a positive integer [an array of data items capable of being ordered] Algorithm Body: for to
for to n
if then next i if then
next k Output: [in ascending order]The action of selection sort can be represented pictorially as follows:
kth step: Find the index of the array element with minimum value from among . If the value of this array element is less than the value of . then its value and the value of are interchanged.
30. Construct a trace table showing the action of selection sort on the array of exercise 28.
Algorithm to arrange the items in an array in ascending order.
Sorted algorithm for array arrangement.
Algorithm of selection sort
Bartleby provides explanations to thousands of textbook problems written by our experts, many with advanced degrees!Get Started