Assume we are using quicksort to sort an array in ascending
Assume we are using quicksort to sort an array in ascending order. Into which array location does quicksort’s strategy place a pivot element after partitioning?
lowest index in array still available
highest index in array still available
closer to its correct final location
its final correct location
1 points
QUESTION 2
Complete the following code that is intended to provide a comparator interface that will be used to create an object that implements the Comparator interface so that object can compare Auto objects.
public class Comparator<Auto>
public class Comparator<Auto> implements Comparator
public interface Auto<Comparator>
public interface Comparator<Auto>
1 points
QUESTION 3
Which selection sort iteration guarantees the array is sorted for a 10-element array?
9th iteration
10th iteration
1st iteration
impossible to tell
1 points
QUESTION 4
In the textbook, we found that the number of element visits for merge sort totaled
n + 5nlog2n. Let’s consider sorting 1024 elements. How many visits are needed?
1.024
6,144
51,200
52,224
1 points
QUESTION 5
Can you search the following array using binary search?
Yes. Binary search can be applied to any array.
No. Binary search can be applied to a sorted array only.
Yes, but the algorithm runs slower because the array is in descending order.
No, negative numbers are not allowed because they indicate that a value is not present.
1 points
QUESTION 6
Given the following code snippet for searching an array:
What value will pos have when this code is executed?
0
1
-1
-2
1 points
QUESTION 7
Suppose you have a phone number and need to find the address that it corresponds to. If there are 2,000,000 entries, how many do you expect to search in a printed phone directory before finding the address you are looking for?
Approximately 50,000 records.
Approximately 75,000 records.
Approximately 1,000,000 records.
Approximately 1,200,000 records.
1 points
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.
1 points
QUESTION 9
Suppose an array has n elements. We visit element #1 one time, element #2 two times, element #3 three times, and so forth. How many total visits will there be?
2n
n(n+1)/2
n2
n3
1 points
QUESTION 10
After one iteration of selection sort working on an array of 10 elements, what must hold true?
The array cannot be sorted.
One element must be correctly placed.
At least two elements are correctly placed.
The largest element is correctly placed.
1 points
QUESTION 11
If the Arrays static method binarySearch is called on an array of 10 elements and returns a value of 10, what can be concluded?
I the element is not found
II that value cannot be returned from method binarySearch
III if added, the element would be the largest element in the array
I
II
III
I and III
1 points
QUESTION 12
A version of which sort algorithm is used in the sort method in the Java Arrays class?
merge sort
quicksort
selection sort
insertion sort
1 points
QUESTION 13
Consider the following code snippet:
What sort algorithm is used in this code?
insertion sort
selection sort
merge sort
quicksort
1 points
QUESTION 14
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
1 points
QUESTION 15
If a call to the Arrays static method binarySearch returns a value of -10, what can be concluded?
I the element is not in the array
II the element is at index 10
III the element can be inserted at index 9
I
II
III
I and III
1 points
QUESTION 16
Another name for linear search is ____ search.
sorted
sequential
random
binary
1 points
QUESTION 17
After 9 iterations of selection sort working on an array of 10 elements, what must hold true?
The largest element is correctly placed by default.
One more iteration is needed to complete the sort.
The smallest element is incorrectly placed.
The largest element is incorrectly placed.
1 points
QUESTION 18
Suppose a developer gets class XYZ files and documentation from a subcontractor. This class does not implement the Comparable interface. What must be true in order for the developer to sort an array of XYZ objects without modifying the xyz class?
The XYZ class must implement the Sortable interface.
XYZ objects must be randomly distributed.
XYZ objects must be ordered.
The developer must supply a comparator object belonging to a class that implements the Comparator<XYZ> interface.
1 points
QUESTION 19
Consider an array with n elements. If we visit each element n times, how many total visits will there be?
n
2n
nn
n2
1 points
QUESTION 20
Suppose we are using binary search on an array with approximately 1,000,000 elements. How many visits should we expect to make in the worst case?
1
16
20
30
1 points
Click Save and Submit to save and submit. Click Save All Answers to save all answers.
| lowest index in array still available | ||
| highest index in array still available | ||
| closer to its correct final location | ||
| its final correct location |
Solution
1. highest index in array still available
2. public class Comparator<Auto> implements Comparator
3. 9th iteration
4. 6,144
5. Yes, but the algorithm runs slower because the array is in descending order.
6. 1
7. Approximately 75,000 records.
8. The largest element in the array.
9. n(n+1)/2
10. At least two elements are correctly placed.
11. I and III
12. selection sort
13. quicksort
14. I and II
15. I and III
16. sequential
17. One more iteration is needed to complete the sort.
18. XYZ objects must be randomly distributed.
19. 2n
20. 20





