In this problem we want by swapping elements o Here is the main idea: fi element. This element sl algorithm swaps the sma part of the array, and the finding the smallest eler at index 1. Now subarra part of the array from in Repeat the process until
In this problem we want by swapping elements o Here is the main idea: fi element. This element sl algorithm swaps the sma part of the array, and the finding the smallest eler at index 1. Now subarra part of the array from in Repeat the process until
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
Related questions
Question
![13
Problem 1B
In this problem we want to do an "in-place" sorting, that is, given an unsorted array, sort the array directly,
by swapping elements on the array, without using and returning another array.
Here is the main idea: first scan through the original input array from index 0 to the end, finding the smallest
element. This element should be the first element of the sorted array. To make it the first element of the array, the
algorithm swaps the smallest element with the element at index 0. Now, subarray at index 0 is considered the sorted
array, and the rest is unsorted. Next, scan through the unsorted part of the array, from index 1 to the end,
finding the smallest element in the range. Then make it the 2nd element of the array by swapping it with the element
at index 1. Now subarray at index 0 and index 1 are sorted, and the rest are unsorted. Next, scan through the unsorted
part of the
part of the array from index 2 to the end, finding the smallest element and put it as the 3rd element of the array.
Repeat the process until no more unsorted subarray exists. Following figure shows the steps of sorting an array.
swap.
29
72 98
13
87 66 52
51
36
13 is smallest
-swap
13
72
98
29
87
66
52
51 36
29 is smallest
swap
In each iteration,
subarray to the left
of the orange
13
29
98
72
87
66 52 51
36
36 is smallest
swap.
13 29
36
72
87
66 52
51
98
S1 is smallest
swap
element is sorted.
72
98
S2 is smallest
From orange
13
29
36
51
87
66
52
no swap
element to the end
87 72 98
66 is smallest
no swapping
is the unsorted
subarray
29
36
51
52
66
Ldems-
13 29
36 51 52 66
87
72
98
72 is smallest
no swap
98
52 66 | 72 |87
87 is smallest
no swapping
13 29
36 51
13 29
36 51
52 66
72
87
98
sorting completed](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fdac761a6-ba1c-4b50-93cd-f82ea0746880%2Fcb4e9d0b-adc8-4582-8274-826e40434c5e%2F9ntu9ic_processed.jpeg&w=3840&q=75)
Transcribed Image Text:13
Problem 1B
In this problem we want to do an "in-place" sorting, that is, given an unsorted array, sort the array directly,
by swapping elements on the array, without using and returning another array.
Here is the main idea: first scan through the original input array from index 0 to the end, finding the smallest
element. This element should be the first element of the sorted array. To make it the first element of the array, the
algorithm swaps the smallest element with the element at index 0. Now, subarray at index 0 is considered the sorted
array, and the rest is unsorted. Next, scan through the unsorted part of the array, from index 1 to the end,
finding the smallest element in the range. Then make it the 2nd element of the array by swapping it with the element
at index 1. Now subarray at index 0 and index 1 are sorted, and the rest are unsorted. Next, scan through the unsorted
part of the
part of the array from index 2 to the end, finding the smallest element and put it as the 3rd element of the array.
Repeat the process until no more unsorted subarray exists. Following figure shows the steps of sorting an array.
swap.
29
72 98
13
87 66 52
51
36
13 is smallest
-swap
13
72
98
29
87
66
52
51 36
29 is smallest
swap
In each iteration,
subarray to the left
of the orange
13
29
98
72
87
66 52 51
36
36 is smallest
swap.
13 29
36
72
87
66 52
51
98
S1 is smallest
swap
element is sorted.
72
98
S2 is smallest
From orange
13
29
36
51
87
66
52
no swap
element to the end
87 72 98
66 is smallest
no swapping
is the unsorted
subarray
29
36
51
52
66
Ldems-
13 29
36 51 52 66
87
72
98
72 is smallest
no swap
98
52 66 | 72 |87
87 is smallest
no swapping
13 29
36 51
13 29
36 51
52 66
72
87
98
sorting completed
![Develop flowchart for this in-place sorting algorithm,
Hint: you will need nested loops for doing the work in one algorithm.
For swapping two elements, create a variable temp to hold one of the values temporarily.
Save the flowchart as img_01B.jpg
• Implement the algorithm using JavaScript
Complete function problemlB() in JS file, attach the onclick event to the corresponding html button
Your implementation should match your flowchart
Sample output (each run will generate a different input array)
49,71,85,19,29,43,20,78,29,40
19,20, 29, 29, 40, 43, 49,71, 78,85
problem1A- aroy sort
problem18 array sort [in-place]
problermB array search
problem3A-- string compare (same length]
problem38 string compare](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fdac761a6-ba1c-4b50-93cd-f82ea0746880%2Fcb4e9d0b-adc8-4582-8274-826e40434c5e%2Ftjqtzyq_processed.jpeg&w=3840&q=75)
Transcribed Image Text:Develop flowchart for this in-place sorting algorithm,
Hint: you will need nested loops for doing the work in one algorithm.
For swapping two elements, create a variable temp to hold one of the values temporarily.
Save the flowchart as img_01B.jpg
• Implement the algorithm using JavaScript
Complete function problemlB() in JS file, attach the onclick event to the corresponding html button
Your implementation should match your flowchart
Sample output (each run will generate a different input array)
49,71,85,19,29,43,20,78,29,40
19,20, 29, 29, 40, 43, 49,71, 78,85
problem1A- aroy sort
problem18 array sort [in-place]
problermB array search
problem3A-- string compare (same length]
problem38 string compare
Expert Solution
![](/static/compass_v2/shared-icons/check-mark.png)
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 2 steps with 1 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
Knowledge Booster
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](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
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)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
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)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education