Show the steps of bubble sort following the example of the solved problems on the handout for the algorithm and the format of your answer. Stop after the first pass with no swaps. 2.1 2.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
100%

c++

2
Show the steps of bubble sort following the example of the solved problems on the handout for the algorithm
and the format of your answer. Stop after the first pass with no swaps.
2.1
2.2
initial values 8 5 3 10 2
i = 4
i= 3
i=2
i=1
initial values 40
i = 4
i=3
i = 2
i=1
42 -3 10 0
Transcribed Image Text:2 Show the steps of bubble sort following the example of the solved problems on the handout for the algorithm and the format of your answer. Stop after the first pass with no swaps. 2.1 2.2 initial values 8 5 3 10 2 i = 4 i= 3 i=2 i=1 initial values 40 i = 4 i=3 i = 2 i=1 42 -3 10 0
Sorting
This handout explains three quadratic sorting algorithms. Each explanation assumes we are sorting an array of size n in
ascending order from position 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.)
■ Corrolary 1: After pass 1, we know that elements 1 through n-1 are sorted and in their correct place in the
array.
■
Corrolary 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.
initial
60 50 40 30 20
values
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
initial
values
10 40 30
60 50
i=4
10
50 60
50 60
i=3
10 30 40
i=2 DONE: no swaps on previous pass
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 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.) ■ Corrolary 1: After pass 1, we know that elements 1 through n-1 are sorted and in their correct place in the array. ■ Corrolary 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. initial 60 50 40 30 20 values 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 initial values 10 40 30 60 50 i=4 10 50 60 50 60 i=3 10 30 40 i=2 DONE: no swaps on previous pass
Expert Solution
Step 1

 Note: As per instructions, the step-by-step procedure/calculation for given values/array is shown in this solution.

 

 

Given data:

  • 2.1:
    • Array = {8,5,3,10,2}

 

  • 2.2:
    • Array = {40,42,-3,10,0} 

 

 

To do:

  • Show steps of Bubble sort
steps

Step by step

Solved in 6 steps

Blurred answer
Knowledge Booster
Randomized Select Algorithm
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