Exam 14: Sorting and Searching

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

The code segment below displays a table of numbers. Select an expression to complete the code segment, so that the resulting algorithm has O(n2) running time. for (int k = 1; k <= n; k++) { For _______________________ { System.out.print(j + " "); } System.out.println(); }

(Multiple Choice)
4.8/5
(43)

In the worst case, quicksort is a(n) ____ algorithm.

(Multiple Choice)
4.9/5
(44)

Suppose an array has n elements. We visit element #1 one time, element #2 two times, element #3 three times, and so forth. How many total visits will there be?

(Multiple Choice)
4.7/5
(50)

An algorithm that tests whether the first array element is equal to any of the other array elements would be an ____ algorithm.

(Multiple Choice)
4.8/5
(30)

Which selection sort iteration guarantees the array is sorted for a 10-element array?

(Multiple Choice)
4.8/5
(43)

Suppose we are using binary search on an array with approximately 1,000,000 elements. How many visits should we expect to make in the worst case?

(Multiple Choice)
4.7/5
(32)

Which of the sorts in the textbook can be characterized by the fact that the best case will have a running time of θ(n) if the data is already sorted? I quicksort II selection sort III insertion sort

(Multiple Choice)
4.8/5
(40)

If the array is already sorted, what is the performance of insertion sort?

(Multiple Choice)
4.9/5
(41)

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

(Multiple Choice)
4.9/5
(37)

Consider the sort method for selection sort shown below: public static void sort (int[]A) An exception would occur

(Multiple Choice)
4.9/5
(40)

What is the worst-case performance of insertion sort?

(Multiple Choice)
4.8/5
(35)

Consider the sort method shown below for selection sort: public static void sort (int[]A) An exception would occur.

(Multiple Choice)
4.7/5
(34)

If a call to the Arrays static method binarySearch returns a value of 7, what can be concluded? I the element is not in the array II the element is at index 7 III the element occurs 7 times in the array

(Multiple Choice)
4.8/5
(32)

What type of algorithm places elements in order?

(Multiple Choice)
4.8/5
(35)

In big-Oh notation, suppose an algorithm requires an order of n3 element visits. How does doubling the number of elements affect the number of visits?

(Multiple Choice)
4.7/5
(48)

Consider the swap method shown below from the SelectionSorter class. If we modified it as shown in the swap2 method shown below, what would be the effect on the sort method? private static void swap(int[] a, int i, int j) { Int temp = a[i]; A[i] = a[j]; A[j] = temp; } Private static void swap2(int[] a, int i, int j) { A[i] = a[j]; A[j] = a[i]; }

(Multiple Choice)
4.8/5
(45)

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.9/5
(31)

Another name for linear search is ____ search.

(Multiple Choice)
4.7/5
(27)

In the textbook, we determined that the merge method requires a total of 5n visits. We found that the number of visits required to sort an array of n elements is T(n) = T(n / 2) + T(n / 2) + 5n. What does T(n / 2) describe?

(Multiple Choice)
4.7/5
(42)

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

(Multiple Choice)
4.8/5
(39)
Showing 61 - 80 of 109
close modal

Filters

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