Question: QUESTION 11 Which of the following classes implement the Comparable interface? I Date II Collections III String I I and II I and III II

QUESTION 11

Which of the following classes implement the Comparable interface?

I Date

II Collections

III String

I

I and II

I and III

II and III

QUESTION 12

Can you search the following array using binary search?

int[] A = {6, 5, 4, 2, 0, 1, -1, -17}; 

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.

QUESTION 13

Consider the sort method for selection sort shown below:

public static void sort (int[] a) 
{ 
 for (int i = 0; i < a.length  1; i++) 
 { 
 int minPos = minimumPosition(i); 
 swap(minPos, i); 
 } 
} 

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.

QUESTION 14

Consider the sort method shown below for selection sort:

public static void sort(int[] a) 
{ 
 for (int i = 0; i < a.length  1; i++) 
 { 
 int minPos = minimumPosition(i); 
 swap(minPos, i); 
 } 
} 

Suppose we modify the loop condition to read i < a.length. What would be the result?

An exception would occur.

The sort would work, but run one more iteration.

The sort would work but with one less iteration.

The sort would work exactly the same as before the code modification.

QUESTION 15

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.

QUESTION 16

What type of algorithm places elements in order?

sorting

searching

insertion

deletion

QUESTION 17

Assume we are using quicksort to sort an array in ascending order. What can we conclude about the indexes of two pivot elements placed in consecutive recursive calls?

They are randomly located.

They are in different halves of the array.

They are both in the same half of the array.

They are adjacent.

QUESTION 18

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; 
} 

sorted

binary

linear

random

QUESTION 19

The performance of an algorithm is most closely related to what?

The total number of element visits

The total number of elements

The type of elements

The number of lines of code in the method

QUESTION 20

The ____ class contains a sort method that can sort array lists.

Sorting

Arrays

Collections

Linear

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!