   Chapter 11.3, Problem 23ES ### 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

# Construct a trace table showing the action of insertion sort on the array of exercise 21.

To determine

Construct a trace showing the action of insertion sort on the array of a = 7, a = 3, a = 6, a = 9, and a = 5.

Explanation

Given information:

a = 7, a = 3, a = 6, a = 9, and a = 5

Calculation:

a=7

a=3

a=6

a=9

a=5

Initial order:

Initially, we have been given 5 elements and thus the value 5 is assigned to n.

We have been given a=7,a=3,a=6,a=9,a=5.

We initially set k to 2, x to a[k]=a=3 and j to k1=21=1.

We add this information in a table.

 Iteration n a a a a a k x j 0 5 7 3 6 9 5 2 3 1

First step:

In the first step, we compare the second element a=3 to the first element a=7.

Since the second element 3 is smaller than the first element 7, we need to assign the 7 as the second element and then j is decreased by 1.

Next, we then assign the 3 as the first element.

 Iteration n a a a a a k x j 0 5 7 3 6 9 5 2 3 1 1 7 0 2 3

Second step:

In the second step, we compare the third element a=6 to the first element a=3 and to the second element a=7. k is increased by 1, while x is set to a[k]=a=6 and j to k1=31=2.

Since the third element 6 is larger than the second element 7, we move the second element to the third element. j is then decreased by 1.

Since the original third element 6 is larger than the first element 3, we need to add the original third element as the second element.

 Iteration n a a a a a k x j 0 5 7 3 6 9 5 2 3 1 1 7 0 2 3 3 3 6 2 4 7 1 5 6 0

Third step:

In the third step, we compare the fourth element a=9 to the first element a=3, the second element a=6 and the third element a=7

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