   Chapter 11.3, Problem 30ES ### Discrete Mathematics With Applicat...

5th Edition
EPP + 1 other
ISBN: 9781337694193

#### Solutions

Chapter
Section ### Discrete Mathematics With Applicat...

5th Edition
EPP + 1 other
ISBN: 9781337694193
Textbook Problem
1 views

# 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 ] < 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.

To determine

Algorithm to arrange the items in an array in ascending order.

Explanation

Given information:

a=6,a=4,a=5,a=8 and a=1

Concept used:

Sorted algorithm for array arrangement.

Calculation:

 a[n] Stored value a 6 a 4 a 5 a 8 a 1

Algorithm of selection sort

fork:=1 to n1IndexOfMin:=kfori:=K+1 to nif (a[i]<a[IndexOfMin])thenIndexOfMin:=inextiifIndexOfMink thenTemp:=a[k]a[k]:=a[IndexOfMin]a[IndexOfMin]:=Tempnextk

 n 5 a[n] 5 2 a 3

### Still sussing out bartleby?

Check out a sample textbook solution.

See a sample solution

#### The Solution to Your Study Problems

Bartleby provides explanations to thousands of textbook problems written by our experts, many with advanced degrees!

Get Started 