
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Question
the qusetion on the picture
![Question 1:
The following algorithm takes an unsorted array of integer numbers as input and sorts it in
descending order, by repeatedly doing the following:
first, it searches in the whole array for the greatest element.
it then puts this element to the beginning of the array.
then, it searches the whole array excluding the first element for the greatest value and puts
it to the second position.
Implement the algorithm according to two diffrent strategies:
A. By using the method shiftRight(int[] A, int i, int j): if the maximum element is
found in position j and needs to be put into position i, then (i) shift A to the right,
starting from position i, while remembering the element in position j that will be
overridden; (i) copy the remembered element to position i.
B. By using the method swap(int[] A, int i, int j): if the maximum element is found in
position i and needs to be put into position j, then use swap to exchange the element
in position i with the element in position j.
Question 2:
Find out which of the two algorithms is faster. Is there an array size for which the running times
crosse over? (A size N would be such a cross-over point if for inputs of size less than N, the running
times of one algorithm are better, while for inputs of size greater than N, the running times of the
other algorithm are better.)
To perform your measurements, write a test class that
1. creates random arrays of size n = 10, 100, 1000, etc., and
2. for each array created, sorts it using the two implementations of the algorithm and
measures the running times.
to measure the running time use the Java method System.nanoTime() in the
following way:
long startTime = System.nanoTime();
. the code being measured .
long estimatedTime = System.nanoTime()-startTime;](https://content.bartleby.com/qna-images/question/77f5f1dd-3347-4fc1-abac-3e92aa821954/431c7c99-13da-476f-82f0-ac14f7daf851/lxh72l1_thumbnail.jpeg)
Transcribed Image Text:Question 1:
The following algorithm takes an unsorted array of integer numbers as input and sorts it in
descending order, by repeatedly doing the following:
first, it searches in the whole array for the greatest element.
it then puts this element to the beginning of the array.
then, it searches the whole array excluding the first element for the greatest value and puts
it to the second position.
Implement the algorithm according to two diffrent strategies:
A. By using the method shiftRight(int[] A, int i, int j): if the maximum element is
found in position j and needs to be put into position i, then (i) shift A to the right,
starting from position i, while remembering the element in position j that will be
overridden; (i) copy the remembered element to position i.
B. By using the method swap(int[] A, int i, int j): if the maximum element is found in
position i and needs to be put into position j, then use swap to exchange the element
in position i with the element in position j.
Question 2:
Find out which of the two algorithms is faster. Is there an array size for which the running times
crosse over? (A size N would be such a cross-over point if for inputs of size less than N, the running
times of one algorithm are better, while for inputs of size greater than N, the running times of the
other algorithm are better.)
To perform your measurements, write a test class that
1. creates random arrays of size n = 10, 100, 1000, etc., and
2. for each array created, sorts it using the two implementations of the algorithm and
measures the running times.
to measure the running time use the Java method System.nanoTime() in the
following way:
long startTime = System.nanoTime();
. the code being measured .
long estimatedTime = System.nanoTime()-startTime;
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution
Trending nowThis is a popular solution!
Step by stepSolved in 2 steps with 1 images

Knowledge Booster
Similar questions
- x = zeros(uint8(5,5)); for i = 1:5 for j = 1:5 a = 5/i; x(i,j) = 255/a; end end Which of the following best describes the black and white image x? 1. The columns of x will get lighter from left to right 2. The rows of x will get lighter from top to bottom 3. The rows of x will get darker from top to bottom 4. The columns of x will get darker from left to rightarrow_forwardUsing code in C u can open image in new tab so can you can see clearly because I can only post 2 images SONGS LIST IDGAF - Dua LipaFRIENDS - Marshmello, Anne-MarieThe Middle - Zedd, Maren Morris, GreyBest Part - H.E.R., Daniel CaesarAll The Stars (with SZA) - Kendrick Lamar, LZAWolves - Selena Gomez, MarshmelloGod's Plan - DrakeRewrite The Stars - Zac Efron, ZendayaHavana - Camila Cabello, Young ThugPerfect - Ed Sheeranarrow_forward2. drawShape(Turtle, sides, length): Draws the polygon based on the user input of # of sides and lenght of the side.arrow_forward
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education

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)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON

Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education