QUESTION 1 If you increase the size of a dataset fivefold ho

QUESTION 1

If you increase the size of a dataset fivefold, how much longer does it take to sort it with the selection sort algorithm?

Approximately 5 times longer

Approximately 20 times longer

Approximately 25 times longer

Approximately 100 times longer

QUESTION 2

Consider the following code snippet:

What sort algorithm is used in this code?

insertion sort

selection sort

merge sort

quicksort

QUESTION 3

Given the following code snippet for searching an array:

What value will pos have when this code is executed?

5

-5

6

-6

QUESTION 4

Choose the order of the following growth rates, from slowest to fastest: (n3), (nlog(n)), (n3/2), (2n).

(n log(n)), (n3/2), (n3), (2n)

(n3), (n log(n)), (n3/2), (2n)

(n3/2), (n log(n)), (n3), (2n)

(2n), (n3), (n3/2), (n log(n))

QUESTION 5

Which of the following arrays can be used in a call to the Arrays.sort method?

I Any array with primitive numeric data, such as int, double, …

II Arrays of String or numeric wrapper classes like, Integer, Double, …

III Any class that implements the Comparable interface

I

II

I and II

I, II and III

QUESTION 6

Consider the minimumPosition method from the SelectionSorter class. Complete the code to write a maximumPosition method that returns the index of the largest element in the range from index from to the end of the array.

if(a[i] > a[maxPos]) { maxPos = i; }

if(a[i] == a[maxPos]) { maxPos = i; }

if(a[i] < a[maxPos]) { maxPos = i; }

if(a[i] <= a[maxPos]) { maxPos = i; }

QUESTION 7

Which sort algorithm starts by cutting the array in half and then recursively sorts each half?

insertion sort

selection sort

merge sort

quicksort

QUESTION 8

In each iteration, selection sort places which element in the correct location?

The smallest in the array.

The smallest element not yet placed in prior iterations.

The largest element in the array.

A random element.

QUESTION 9

Given the following code snippet for searching an array:

What value will pos have when this code is executed?

0

1

-1

-2

QUESTION 10

In the textbook, we determined that the merge method requires a total of 5n visits. We found that the number of visits required to sort an array of n elements is T(n) = T(n / 2) + T(n / 2) + 5n. What does T(n / 2) describe?

the total number of visits to merge sort an array of n elements

half the number of visits to merge sort an array of n elements

the total number of visits to merge sort an array of n / 2 elements

half the number of visits to merge sort an array of n / 2 elements

Approximately 5 times longer

Approximately 20 times longer

Approximately 25 times longer

Approximately 100 times longer

Solution

1) Approximately 25 times longer because of n2 => 52 = 25
2) insertion sort
3) -5 [Means at 5th place 15 can be inserted as it is not present so the negative index is returned]
4) (n log(n)), (n3/2), (n3), (2n)
5) I, II and III
6) if(a[i] > a[maxPos]) { maxPos = i; }
7) merge sort, starts by cutting into half
8) The smallest in the array.
9) -1 [because when the element is not present it tells us that where the element can be placed in negative value , so its -1 because 15 is the lower most element can be placed at first index]
10) the total number of visits to merge sort an array of n / 2 elements



Thanks, let me know if there is any concern.

QUESTION 1 If you increase the size of a dataset fivefold, how much longer does it take to sort it with the selection sort algorithm? Approximately 5 times long
QUESTION 1 If you increase the size of a dataset fivefold, how much longer does it take to sort it with the selection sort algorithm? Approximately 5 times long
QUESTION 1 If you increase the size of a dataset fivefold, how much longer does it take to sort it with the selection sort algorithm? Approximately 5 times long

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site