Practice Exam Questions to Review Flashcards

1
Q

In a Java merge sort, the unsorted array is recursively divided into subarrays until the subarray size is _____.

A

The unsorted array is recursively divided until the subarray becomes single element subarray whose size is one.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

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

A

if (left>=right)

The test for the end condition is the test just before the return statement, where the routine begins to unwind.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

When multiplying matrices, we start at the first _____ of the first matrix and the first _____ of the second.

A

row, column

In mathematics and Java we walk across the rows and down the columns.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

A Java string is a ___________.

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

A computer program can be best described as ____________________.

A

A set of instructions or programs designed to complete a particular task.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What data types are allowed in a Java switch statement?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Why does Java prevent the use of multiple inheritance?

A

Ambiguity, diamond problem, and low usage frequency.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the best case complexity of merge sort?

A

The best case complexity of merge sort is Ω(n log n).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

The average case performance of selection sort is:

A

O(n^2)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

int rNew = r.nextInt(5);

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

correctly insert the integer value 247 into the third element of the ArrayList pCode?

A

pCode.add(2, 247);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Categories for operators:

A

operational, relational, logical

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

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

}

}

A

price p = new price();
p.quote(2,3);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

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();

A

this.action();

How well did you know this?
1
Not at all
2
3
4
5
Perfectly