Exam 14: Sorting and Searching
Exam 1: Introduction98 Questions
Exam 2: Using Objects76 Questions
Exam 3: Implementing Classes103 Questions
Exam 4: Fundamental Data Types125 Questions
Exam 5: Decisions120 Questions
Exam 6: Loops128 Questions
Exam 7: Arrays and Array Lists118 Questions
Exam 8: Designing Classes95 Questions
Exam 9: Inheritance101 Questions
Exam 10: Interfaces85 Questions
Exam 11: Inputoutput and Exception Handling109 Questions
Exam 12: Object-Oriented Design104 Questions
Exam 13: Recursion110 Questions
Exam 14: Sorting and Searching109 Questions
Exam 15: The Java Collections Framework110 Questions
Exam 16: Basic Data Structures104 Questions
Exam 17: Tree Structures110 Questions
Exam 18: Generic Classes75 Questions
Exam 19: Graphical User Interfaces76 Questions
Exam 20: Streams and Binary Inputoutput82 Questions
Exam 21: Multithreading82 Questions
Exam 22: Internet Networking74 Questions
Exam 23: Relational Databases75 Questions
Exam 24: XML74 Questions
Exam 25: Web Applications75 Questions
Select questions type
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?
Free
(Multiple Choice)
4.9/5
(38)
Correct Answer:
D
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?
Free
(Multiple Choice)
4.9/5
(34)
Correct Answer:
D
Suppose objects a and b are from a user-defined class that implements the Comparable interface. What must be true about the return value of a.compareTo(b) for the compareTo method that this class implements?
Free
(Multiple Choice)
4.8/5
(44)
Correct Answer:
D
Given the following code snippet for searching an array:
Int[] arr = {23, 25, 29, 34, 42};
Int newVal = 15;
Int pos = Arrays.binarySearch(arr, newVal);
What value will pos have when this code is executed?
(Multiple Choice)
4.8/5
(28)
The partial linear search method below is designed to search an array of String objects. Select the expression that would be needed to complete the method. public static int search(String[] a, String item)
{
For (int i = 0; i < a.length; i++)
{
If ( ____________________________ )
{
Return i;
}
Return -1;
}
}
(Multiple Choice)
4.8/5
(25)
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. ___________________________
{
Int compare(Auto a, Auto B); }
(Multiple Choice)
4.9/5
(38)
The performance of an algorithm is most closely related to what?
(Multiple Choice)
4.9/5
(35)
Which of the following statements about running times of algorithms is correct?
(Multiple Choice)
4.8/5
(40)
The largestPosition method below returns the index of the largest element in the tail range of an array of integers. Select the expression that would be needed to complete the selectionSort method below, so that it sorts the elements in descending order. /**
Finds the largest element in the tail range of an array.
@param a the array to be searched
@param from the first position in a to compare
@return the position of the largest element in range a[from]..a[a.length - 1]
*/
Private static int largestPosition(int[] a, int from)
{
Int maxPos = from;
For (int j = from + 1; j < a.length; j++)
{
If (a[j] > a[maxPos])
{
MaxPos = j;
}
}
Return maxPos;
}
Public static void selectionSort(int[]A) (int i = 0; i < a.length - 1; i++)
(Multiple Choice)
4.9/5
(40)
Which of the following classes implement the Comparable interface?
I Date
II Collections
III String
(Multiple Choice)
5.0/5
(38)
Suppose you wish to implement the Comparable interface to allow your Vehicle class to compare Auto objects only. Which of the following is the correct way to do this?
(Multiple Choice)
4.8/5
(41)
The following code is an example of a ___ search. public static int search(int[] a, int v)
{
For (int i = 0; i < a.length; i++)
{
If (a[i] == v) { return i; }
}
Return -1;
}
(Multiple Choice)
4.9/5
(34)
In general, the expression ____ means that f grows no faster than g.
(Multiple Choice)
4.9/5
(44)
A portion of your program includes the method shown in the code snippet below to examine the elements of an array arr: private int findElement(int[] arr, int newVal)
{
Int pos = Arrays.binarySearch(arr, newVal);
Return pos;
}
What can you conclude about the running time of this section of code?
(Multiple Choice)
4.9/5
(44)
The ____ class contains a sort method that can sort array lists.
(Multiple Choice)
4.8/5
(35)
How many times can an array with 4,096 elements be cut into two equal pieces?
(Multiple Choice)
4.7/5
(40)
When does quicksort's worst-case run-time behavior occur?
I when the data is randomly initialized in the array
II when the data is in ascending order
III when the data is in descending order
(Multiple Choice)
4.9/5
(36)
Assume that names is an array of String objects that has been initialized with a large number of elements. Select the statement that would sort the elements in names in ascending alphabetic order.
(Multiple Choice)
4.8/5
(35)
Which of the sorts in the textbook can be characterized by the fact that even in the worst case the running time will be O(n log(n)))?
I quicksort
II selection sort
III merge sort
(Multiple Choice)
4.8/5
(43)
Showing 1 - 20 of 109
Filters
- Essay(0)
- Multiple Choice(0)
- Short Answer(0)
- True False(0)
- Matching(0)