42. Consider the two methods below? public static void sort (ArrayList list) { for (int p = 0; p < list.size(); p++) { } int smallest = p; for (int q = p+1; q list, int x, int y) { int temp = list.get(x); list.set(x,list.get(y)); list.set(y,temp); 42. Which of the following sorts is implemented above? Bubble Sort Selection Sort Insertion Sort Merge Sort None of the above

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

all questions are in the pics, thanks!

42. Consider the two methods below?
public static void sort (ArrayList<Integer> list)
{
for (int p = 0; p < list.size(); p++)
{
int smallest = p;
for (int q = p+1; q < list.size(); q++)
{
if (list.get(q) < list.get(smallest))
{
smallest = q;
}
}
swap(list,p,smallest);
}
}
private static void swap (ArrayList<Integer> list, int x, int y)
{
int temp = list.get(x);
list.set(x,list.get(y));
list.set(y,temp);
42. Which of the following sorts is implemented above?
Bubble Sort
Selection Sort
Insertion Sort
Merge Sort
None of the above
Transcribed Image Text:42. Consider the two methods below? public static void sort (ArrayList<Integer> list) { for (int p = 0; p < list.size(); p++) { int smallest = p; for (int q = p+1; q < list.size(); q++) { if (list.get(q) < list.get(smallest)) { smallest = q; } } swap(list,p,smallest); } } private static void swap (ArrayList<Integer> list, int x, int y) { int temp = list.get(x); list.set(x,list.get(y)); list.set(y,temp); 42. Which of the following sorts is implemented above? Bubble Sort Selection Sort Insertion Sort Merge Sort None of the above
43. Consider the code segment and sort method below.
ArrayList<Integer> list = new ArrayList<Integer>();
for (int k = 1; k <= 20; k++)
{
}
sort(list);
for (int item: list)
int rnd = (int) (Math.random() * 90 + 10);
list.add(rnd);
}
System.out.println();
public static void sort (ArrayList<Integer> list)
{
System.out.print(item + " ");
}
for (int p = 0; p < list.size(); p++)
{
}
int smallest = p;
for (int q = p+1; q < list.size(); q++)
if (list.get(q) < list.get(smallest))
smallest = q;
swap(list,p,smallest);
private static void swap (ArrayList<Integer> list, int x, int y)
{
int temp = list.get(x);
list.set(x,list.get(y));
list.set(y,temp);
43. What can be printed when the program is executed?
11 18 22 22 31 33 41 41 48 57 60 65 72 75 78 81 90 90 92 97
89 89 88 86 86 81 79 69 64 63 57 55 51 51 45 37 33 18 17 15
O 7 11 26 28 29 31 41 43 44 47 50 51 63 64 67 74 89 91 93 97
93 83 70 67 59 57 52 51 40 34 30 27 21 18 18 16 14 11 10 10
Both (B) and (D)
Transcribed Image Text:43. Consider the code segment and sort method below. ArrayList<Integer> list = new ArrayList<Integer>(); for (int k = 1; k <= 20; k++) { } sort(list); for (int item: list) int rnd = (int) (Math.random() * 90 + 10); list.add(rnd); } System.out.println(); public static void sort (ArrayList<Integer> list) { System.out.print(item + " "); } for (int p = 0; p < list.size(); p++) { } int smallest = p; for (int q = p+1; q < list.size(); q++) if (list.get(q) < list.get(smallest)) smallest = q; swap(list,p,smallest); private static void swap (ArrayList<Integer> list, int x, int y) { int temp = list.get(x); list.set(x,list.get(y)); list.set(y,temp); 43. What can be printed when the program is executed? 11 18 22 22 31 33 41 41 48 57 60 65 72 75 78 81 90 90 92 97 89 89 88 86 86 81 79 69 64 63 57 55 51 51 45 37 33 18 17 15 O 7 11 26 28 29 31 41 43 44 47 50 51 63 64 67 74 89 91 93 97 93 83 70 67 59 57 52 51 40 34 30 27 21 18 18 16 14 11 10 10 Both (B) and (D)
Expert Solution
Step 1

42) We have to choose the correct sort method which is implemented in the given code from the options.

43) We have to choose the correct answer from the given options that can be printed when the program is executed.

steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Concept of memory addresses in pointers
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