1 points QUESTION 7 Which sort algorithm starts with an initial sequence of size
ID: 3799682 • Letter: 1
Question
1 points
QUESTION 7
Which sort algorithm starts with an initial sequence of size 1, which is assumed to be sorted, and increases the size of the sorted sequence in the array in each iteration?
insertion sort
selection sort
merge sort
quicksort
1 points
QUESTION 8
A binary search is generally ____ a linear search.
slower than
equal to
less efficient than
faster than
1 points
QUESTION 9
Consider the sort method for selection sort shown below:
Suppose we modify the loop control to read int i = 1; i < a.length – 1; i++. What would be the result?
An exception would occur
The sort would not consider the last array element.
The sort would not consider the first array element.
The sort would still work correctly.
1 points
QUESTION 10
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 11
Suppose you wish to sort an array list of objects, but the object class does not implement the Comparable interface. Because you are not allowed to modify this class, you decide to provide a comparator object that implements the Comparator interface. Which method must you implement from this interface to achieve your objective?
the sort method.
the compare method.
the compareTo method.
the compareObject method.
1 points
QUESTION 12
When the size of an array increases by a factor of 100, the time required by selection sort increases by a factor of ____.
2,000
5,000
10,000
12,000
1 points
QUESTION 13
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 14
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 15
Consider the swap method shown below from the SelectionSorter class. If we modified it as shown in the swap2 method shown below, what would be the effect on the sort method?
There would be no effect.
Some array elements would be overwritten.
It would sort the array in reverse order.
It would still be correct, but run a little faster.
1 points
QUESTION 16
Consider the following code snippet:
What sort algorithm is used in this code?
insertion sort
selection sort
merge sort
quicksort
1 points
QUESTION 17
Given an ordered array with 15 elements, how many elements must be visited in the worst case of binary search?
8
4
3
2
1 points
QUESTION 18
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 19
What is the smallest value of n for which n2> 3n + 4?
6
5
4
3
1 points
QUESTION 20
How many times can an array with 729 elements be cut into three equal pieces?
4
5
6
7
insertion sort
selection sort
merge sort
quicksort
Explanation / Answer
HI, I have answered first 7 questions.
Please repost others in separate post.
Please let me know in case of any issue in answered part.
Q7)
Ans: insertion sort
Q8)
Ans: A binary search is generally faster than a linear search.
Q9. Ans: The sort would not consider the first array element.
Q10. Ans: quicksort
Q11. Ans: the compare method.
Q12. Ans: 10,000, because time complexity of selection sort = O(n^2)
Q13. Ans: I and III
public static int binarySearch(byte[] a, byte key)
index of the search key, if it is contained in the array; otherwise, (-(insertion point) - 1). The insertion point is defined as the point at which the key would be inserted into the array: the index of the first element greater than the key, or a.length if all elements in the array are less than the specified key. Note that this guarantees that the return value will be >= 0 if and only if the key is found.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.