subject

Question: 4 Consider the following correct implementation of the selectionsort algorithm:

public static ArrayList selectionSort(ArrayList arr){ int currentMinIndex; //Line 3 int counter = 0; for (int i = 0; i < arr. size() - 1; i++) //Line 5 { currentMinIndex = i; for (int j = i + 1; j < arr. size(); j++) { if(arr. get(j) < arr. get(currentMinIndex)) //Line 10 { currentMinIndex = j; } } if (i != currentMinIndex) //Line 16 { int temp = arr. get(currentMinIndex); arr. set(currentMinIndex, arr. get(i)); //Line 19 arr. set(i, temp); } } return arr;}

What would be the most effective way to alter this selectionsort algorithm so that an ArrayList would be sorted from greatestto smallest value?

Change Line 3 to int currentMaxIndex;

Change Line 5 to for(int i= arr. size() -1; i > 0; i --)

Change Line 10 to if(arr. get(j) >arr. get(currentMinIndex))

Change Line 16 to if (i > currentMinIndex)

Change Line 19 to arr. set(arr. get(i), currentMinIndex);

Question: 11

Consider the following correct implementation of the insertionsort algorithm:

public static int[] insertionSort(int[] arr){ for (int i = 1; i < arr. length; i++) { int curNumber = arr[i]; int curIndex = i-1; while ( curIndex >= 0 && arr[curIndex] > curNumber) { arr[curIndex+1] = arr[curIndex]; curIndex--; //Line 13 } arr[curIndex + 1] = curNumber; } return arr;}

The following declaration and method call are made in anothermethod in the same class as insertionSort:

int[] nums = {6, 5, 4, 3, 2, 1};list = insertionSort(nums);

How many times is the statement on Line 13 executed as a resultof the call to insertionSort?

5

30

15

16

6

Question: 13

Consider the following correct implementation of the selectionsort algorithm:

1. public static ArrayList selectionSort(ArrayList arr)2. {3. int currentMinIndex;4. int counter = 0;5. for (int i = 0; i < arr. size() - 1; i++)6. {7. currentMinIndex = i;8. for (int j = i + 1; j < arr. size(); j++)9. {10. if(arr. get(j) < arr. get(currentMinIndex))11. {12. currentMinIndex = j;13. }14. }15. if (i != currentMinIndex)16. {17. int temp = arr. get(currentMinIndex);18. arr. set(currentMinIndex, arr. get(i));19. arr. set(i, temp); //Line 1920. }21. }22. return arr;23. }

Given an ArrayList initialized with the values [6, 5, 4, 3, 2,1], how many times does Line 19 execute when the ArrayList issorted using the selection sort algorithm?

6

3

5

30

4

Question: 17

A website organizes its list of contributors in alphabeticalorder by last name. The website’s new manager would prefer thecontributor list to be ordered in reverse alphabetical orderinstead. Which classic algorithm would be best suited to completethis task?

Linear/Sequential Search

Selection Sort

Insertion Sort

None of these algorithms are viable options.

Question: 18

The following method is a search method intended to return theindex at which a String value occurs within an ArrayList:

public int search(ArrayList list, String target) //Line 1{ int counter = 0; while(counter < list. size()) //Line 4 { if(list. get(counter).equals(target)) { return list. get(counter); //Line 8 } counter++; //Line 10 } return -1; //Line 12}

However, there is currently an error preventing the method towork as intended. Which of the following Lines needs to be modifiedin order for the method to work as intended?

Line 1 - The method should be returning a String value, not anint.

Line 4 - The loop should go to < list. size() - 1 so as toavoid an .

Line 8 - The return should be the counter, notlist. get(counter).

Line 10 - As written, the counter will skip every othervalue.

Line 12 - The return value should be a String, not an int.

Question: 19

A company organizes all of its client database in order of theamount of money that the account is worth. When a new account isadded, it is placed in the correct order in the database based onthe worth of the account. Which classic algorithm would be bestsuited to perform this function?

Linear/Sequential Search

Insertion Sort

Selection Sort

None of these are viable options

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 23:30
The next button in the review section shows the next available comment. next slide with no comment. previous comment. edited comment.
Answers: 1
question
Computers and Technology, 23.06.2019 07:00
Why were most movies from the late 1890s until the early 1930s only filmed in black and white? there were only a few people who could afford the technology to produce color motion pictures back then. audiences did not want color motion pictures until later. the film used to make color motion pictures often overheated, which was a safety hazard, so it was generally not allowed. color films had to be hand-colored, frame by frame.
Answers: 3
question
Computers and Technology, 23.06.2019 20:30
If an appliance consumes 500 w of power and is left on for 5 hours, how much energy is used over this time period? a. 2.5 kwh b. 25 kwh c. 250 kwh d. 2500 kwh
Answers: 1
question
Computers and Technology, 24.06.2019 00:00
Consider the series where in this problem you must attempt to use the ratio test to decide whether the series converges. compute enter the numerical value of the limit l if it converges, inf if it diverges to infinity, minf if it diverges to negative infinity, or div if it diverges but not to infinity or negative infinity.
Answers: 1
You know the right answer?
Question: 4 Consider the following correct implementation of the selectionsort algorithm:
Questions
question
Mathematics, 17.06.2021 17:00
question
Mathematics, 17.06.2021 17:00
Questions on the website: 13722363