Practice Exam Questions to Review Flashcards
In a Java merge sort, the unsorted array is recursively divided into subarrays until the subarray size is _____.
The unsorted array is recursively divided until the subarray becomes single element subarray whose size is one.
What is the test for the end condition in the following recursive piece of code?
public void quicksort( int left, int right ) {
int i, last;
if (left >= right )
return;
swap( left, (left + right)/2 );
last = left;
for ( i = left+1; i <= right; i++ )
if ( data[i] < data[left] ) swap( ++last, i );
swap( left, last );
quicksort( left, last-1 );
quicksort( last+1, right );
} // quicksort
if (left>=right)
The test for the end condition is the test just before the return statement, where the routine begins to unwind.
When multiplying matrices, we start at the first _____ of the first matrix and the first _____ of the second.
row, column
In mathematics and Java we walk across the rows and down the columns.
A Java string is a ___________.
Class
The string class has several methods for working with strings; when declaring a string you’re creating a new instance of the string class.
A computer program can be best described as ____________________.
A set of instructions or programs designed to complete a particular task.
What data types are allowed in a Java switch statement?
string, int, short, char
Doubles and floats are not allowed because of precision and rounding issues. However, the switch statement is a very powerful tool for evaluating int, short, char, or Strings.
Why does Java prevent the use of multiple inheritance?
Ambiguity, diamond problem, and low usage frequency.
What is the best case complexity of merge sort?
The best case complexity of merge sort is Ω(n log n).
The average case performance of selection sort is:
O(n^2)
int rNew = r.nextInt(5);
It is an instance of the Random class.
Even though we don’t have the full code, we can assume r would be an instance of the Random class because it invokes the nextInt() function.
correctly insert the integer value 247 into the third element of the ArrayList pCode?
pCode.add(2, 247);
Categories for operators:
operational, relational, logical
In the code below, how can the method quote be called from the method main?
class price {
int quote(int x, int y) {
return x+y;
}
public static void main(String[]args) {
//call quote
}
}
price p = new price();
p.quote(2,3);
Given a class Example with static method called action with no parameters, which of the following is never a correct call for the static method ?
Example.action();
action();
Example ex = new Example();
ex.action();
this.action();
this.action();