Exam 14: Sorting and Searching

arrow
  • Select Tags
search iconSearch Question
flashcardsStudy Flashcards
  • Select Tags

Given an ordered array with 31 elements, how many elements must be visited in the worst case of binary search?

Free
(Multiple Choice)
4.8/5
(35)
Correct Answer:
Verified

C

The analysis for the number of visits in a binary search begins with the equation, T(n) = T(n / 2) + 1. What does the number 1 represent in this equation?

Free
(Multiple Choice)
4.9/5
(28)
Correct Answer:
Verified

A

If you want to use the Comparable interface, you must implement a single method called ____.

Free
(Multiple Choice)
4.9/5
(31)
Correct Answer:
Verified

B

A portion of your program includes the loop shown in the code snippet below to examine the elements of an array arr: Int count = 0; Int targetVal = 70; For (int i = 0; i < arr.length; i++) { If (arr[i] >= targetVal) { Count++; } } What can you conclude about the running time of this section of code?

(Multiple Choice)
4.9/5
(48)

What is the smallest value of n for which n2 > 3n + 4?

(Multiple Choice)
5.0/5
(41)

In general, the expression ____ means that f grows no faster than g.

(Multiple Choice)
4.8/5
(35)

Which sort algorithm starts by partitioning the array and selecting a pivot element?

(Multiple Choice)
4.8/5
(46)

Another name for linear search is ____ search.

(Multiple Choice)
4.8/5
(29)

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

(Multiple Choice)
4.8/5
(32)

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?

(Multiple Choice)
4.8/5
(43)

Which sort algorithm starts by cutting the array in half and then recursively sorts each half?

(Multiple Choice)
4.7/5
(34)

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

(Multiple Choice)
4.7/5
(41)

Which of the following completes the selection sort method minimumPosition()? Private static int minimumPosition(int[] a, int from) { Int minPos = from; For (int i = from + 1; i < a.length; i++) { ________________ } Return minPos; }

(Multiple Choice)
4.8/5
(38)

Suppose objects a and b are from a user-defined class that implements the Comparable interface. Which condition tests the compareTo method's return value to determine that a will precede b when the sort method is called?

(Multiple Choice)
4.8/5
(44)

Which sort algorithm is used in the sort method in the Java Arrays class when the array length is less than 7?

(Multiple Choice)
4.7/5
(40)

After 5 iterations of selection sort working on an array of 10 elements, what must hold true?

(Multiple Choice)
4.9/5
(45)

When the size of an array increases by a factor of 100, the time required by selection sort increases by a factor of ____.

(Multiple Choice)
4.7/5
(35)

If an element is present in an array of length n, how many element visits, on average, are necessary to find it using a linear search?

(Multiple Choice)
4.8/5
(35)

How large does n need to be so 0.3n2 is greater than 2.5n - 3?

(Multiple Choice)
4.9/5
(31)

What is the worst-case performance of insertion sort?

(Multiple Choice)
4.8/5
(41)
Showing 1 - 20 of 99
close modal

Filters

  • Essay(0)
  • Multiple Choice(0)
  • Short Answer(0)
  • True False(0)
  • Matching(0)