 # 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 a [ 1 ] , a [ 2 ] , a [ 3 ] , … , a [ n ] , 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 k = 1 to n − 1 , the kth step of the algorithm selects the index of the array item will, minimum value from among a [ k + 1 ] , a [ k + 2 ] , a [ k + 3 ] , … , a [ n ] . Once this index is found, the value of the corresponding array item is interchanged with the value of a [ k ] unless the index already equals k. At the end of execution the array elements are in order.] Input: n [a positive integer a [ 1 ] , a [ 2 ] , a [ 3 ] , … , a [ n ] [an array of data items capable of being ordered] Algorithm Body: for k : = 1 to n − 1 I n d e x O f M i n : = k for i : = k + 1 to n if ( a [ i ] &lt; a [ I n d e x o f M i n ] ) then I n d e x O f M i n : = i next i if IndexOfMin ≠ k then T e m p : = a [ k ] a [ k ] : = a [ I n d e x O f M i n ] a [ I n d e x O f M i n ] : = T e m p next k Output: a [ 1 ] , a [ 2 ] , a [ 3 ] , … , a [ n ] [ in ascending order] The action of selection sort can be represented pictorially as follows: a [ 1 ] a [ 2 ] ⋯ a [ k ] ↑ a [ k + 1 ] ⋯ a [ n ] kth step: Find the index of the array element with minimum value from among a [ k + 1 ] , … , a [ n ] . If the value of this array element is less than the value of a [ k ] . then its value and the value of a [ k ] are interchanged. 30. Construct a trace table showing the action of selection sort on the array of exercise 28. ### Discrete Mathematics With Applicat...

5th Edition
EPP + 1 other
Publisher: Cengage Learning,
ISBN: 9781337694193 ### Discrete Mathematics With Applicat...

5th Edition
EPP + 1 other
Publisher: Cengage Learning,
ISBN: 9781337694193

#### Solutions

Chapter
Section
Chapter 11.3, Problem 30ES
Textbook Problem

## Expert Solution

### Want to see the full answer?

Check out a sample textbook solution.See solution

### Want to see this answer and more?

Experts are waiting 24/7 to provide step-by-step solutions in as fast as 30 minutes!*

See Solution

*Response times vary by subject and question complexity. Median response time is 34 minutes and may be longer for new subjects. 