   Chapter 11.3, Problem 35ES ### 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.35. Consider applying selection sort to an array a [ 1 ] ,   a [ 2 ] ,   a [ 3 ] ,   ⋯ ,   a [ n ] . a. How many times is the comparison in the if-then statement performed when a [ 1 ] is compared to each of a [ 2 ] ,   a [ 3 ] ,   ⋯ ,   a [ n ] ? b. How many times is the comparison in the if-then statement performed when a [ 2 ] is compared to each of a [ 3 ] ,   a [ 4 ] ,   ⋯ ,   a [ n ] ? c. How many times is the comparison in the if-then statement performed when a [ k ] is compared to each of a [ k − 1 ] ,   a [ k + 2 ] ,   … ,   a [ n ] ? d. Using the number of times the comparison in the if-then statement is performed as a measure of the time efficiency of selection sort, find a worst-case order for selection sort. Use the theorem on polynomial orders.

To determine

(a)

To find out the number of times and order comparison is performed in the execution of the algorithm

Explanation

First step is compare a with a,a.a[n] which are n2+1=n1 elements to which a is compared. This requires one comparison a[i] < a[

To determine

(b)

To find out the number of times and order comparison is performed in the execution of the algorithm

To determine

(c)

To find out the number of times and order comparison is performed in the execution of the algorithm

To determine

(d)

To find out the number of times and order comparison is performed in the execution of the algorithm

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