Show the steps of selection sort following the example of the solved problems on the handout for the algorithm and the format of your answer. Show all rows even for passes that no swaps occur. 4.1 4.2 initial values 8 5 3 10 2 i=4 i=3 i=2 i=1 initial values 40 42 -3 10 0 i = 4 i=3 i= 2 i=1

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

c++

**Sorting**

This handout explains three quadratic sorting algorithms. Each explanation assumes we are sorting an array of size n in ascending order from position [0] through [n-1]. (Technically, we should say "non-decreasing" rather than "ascending", since we could have duplicates.)

**Bubble Sort**

As was demonstrated in class, the main idea of bubble sort is as follows.

- Make n-1 passes through the array, numbered i=n-1, n-2, etc. down to 1
  - On pass i, we consider the part of the array 0 through i:
    - We walk through that part of the array, looking at each pair of adjacent elements and swapping them if they are out of order.
  - We also can keep track of whether any swaps happen during each pass. If we make a pass that has NO swaps at all, we can stop because we know the array is already sorted.

Some things we know about bubble sort:

- After pass i, we know that the element in position i through the end of the array (n-1) is in proper place in the array. (This was explained in lecture.)
  - Corollary 1: After pass 1, we know that elements 1 through n-1 are sorted and in their correct place in the array.
  - Corollary 2: After pass 1, we know the entire array is sorted, because it is not possible for element [0] to be out of place if every other element is in place.

Given this, here are two example "worked problems" for bubble sort.

The part in bold is what YOU would write if given the problem.

**Example 1:**

Initial values: | 60 | 50 | 40 | 30 | 20 |
---|---|---|---|---|---
i=4 | 50 | 40 | 30 | 20 | **60**
i=3 | 40 | 30 | 20 | **50** | 60
i=2 | 30 | 20 | **40** | 50 | 60
i=1 | 20 | 30 | 40 | 50 | 60

**Example 2:**

Initial values: | 10 | 40 | 30 | 60 | 50 |
---|---|---|---|---|---
i=4
Transcribed Image Text:**Sorting** This handout explains three quadratic sorting algorithms. Each explanation assumes we are sorting an array of size n in ascending order from position [0] through [n-1]. (Technically, we should say "non-decreasing" rather than "ascending", since we could have duplicates.) **Bubble Sort** As was demonstrated in class, the main idea of bubble sort is as follows. - Make n-1 passes through the array, numbered i=n-1, n-2, etc. down to 1 - On pass i, we consider the part of the array 0 through i: - We walk through that part of the array, looking at each pair of adjacent elements and swapping them if they are out of order. - We also can keep track of whether any swaps happen during each pass. If we make a pass that has NO swaps at all, we can stop because we know the array is already sorted. Some things we know about bubble sort: - After pass i, we know that the element in position i through the end of the array (n-1) is in proper place in the array. (This was explained in lecture.) - Corollary 1: After pass 1, we know that elements 1 through n-1 are sorted and in their correct place in the array. - Corollary 2: After pass 1, we know the entire array is sorted, because it is not possible for element [0] to be out of place if every other element is in place. Given this, here are two example "worked problems" for bubble sort. The part in bold is what YOU would write if given the problem. **Example 1:** Initial values: | 60 | 50 | 40 | 30 | 20 | ---|---|---|---|---|--- i=4 | 50 | 40 | 30 | 20 | **60** i=3 | 40 | 30 | 20 | **50** | 60 i=2 | 30 | 20 | **40** | 50 | 60 i=1 | 20 | 30 | 40 | 50 | 60 **Example 2:** Initial values: | 10 | 40 | 30 | 60 | 50 | ---|---|---|---|---|--- i=4
The document outlines steps for executing the selection sort algorithm and requests a demonstration of these steps, consistent with the format of solved problems provided in additional materials. Important instructions include displaying each row, even when no swaps occur during a pass.

### 4.1

- **Initial Values:** 8, 5, 3, 10, 2
- **Passes:**
  - \(i = 4\)
  - \(i = 3\)
  - \(i = 2\)
  - \(i = 1\)

### 4.2

- **Initial Values:** 40, 42, -3, 10, 0
- **Passes:**
  - \(i = 4\)
  - \(i = 3\)
  - \(i = 2\)
  - \(i = 1\)

No detailed steps or changes for each pass are provided in the text, indicating that the user is expected to manually execute the sorting process and record the steps accordingly.
Transcribed Image Text:The document outlines steps for executing the selection sort algorithm and requests a demonstration of these steps, consistent with the format of solved problems provided in additional materials. Important instructions include displaying each row, even when no swaps occur during a pass. ### 4.1 - **Initial Values:** 8, 5, 3, 10, 2 - **Passes:** - \(i = 4\) - \(i = 3\) - \(i = 2\) - \(i = 1\) ### 4.2 - **Initial Values:** 40, 42, -3, 10, 0 - **Passes:** - \(i = 4\) - \(i = 3\) - \(i = 2\) - \(i = 1\) No detailed steps or changes for each pass are provided in the text, indicating that the user is expected to manually execute the sorting process and record the steps accordingly.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 6 steps with 2 images

Blurred answer
Knowledge Booster
Mergesort
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education