Exam 14: Sorting and Searching

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

Find the simplest order of growth of the following expression: n3 + log(n5).

(Multiple Choice)
4.8/5
(38)

The partial binary search method below is designed to search an array of String objects sorted in ascending order. Select the expression that would be needed to complete the method. public static int search(String[] a, int low, int high, String item) { If (low <= high) { Int mid = (low + high) / 2; Int result = ____________________________; If (result == 0) { Return mid; } Else if (result < 0) { Return search(a, mid + 1, high, item); } Else { Return search(a, low, mid - 1, item); } } Return -1; }

(Multiple Choice)
4.9/5
(30)

Suppose you wanted to test your sort on an array filled with different elements each time the code is run. What is an efficient technique for creating an array of 1,000 elements for each run?

(Multiple Choice)
4.8/5
(35)

The method checkArray examines an array arr: public static boolean checkArray(int[] arr) { If (arr[0] >= arr[arr.length -1]) { Return true; } Return false; } What can you conclude about the running time of this section of code?

(Multiple Choice)
4.7/5
(34)

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

(Multiple Choice)
4.9/5
(40)

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

(Multiple Choice)
4.8/5
(40)

The merge sort algorithm presented in section 14.4, which sorts an array of integers in ascending order, uses the merge method which is partially shown below. Select the condition that would be needed to complete the method so that the elements are sorted in descending order. private static void merge(int[] first, int[] second, int[] A) { Int iFirst = 0; Int iSecond = 0; Int j = 0; While (iFirst < first.length && iSecond < second.length) { If (_____________________________) { A[j] = first[iFirst]; IFirst++; } Else { A[j] = second[iSecond]; ISecond++; } J++; } // rest of the method follows here }

(Multiple Choice)
4.9/5
(36)

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

Assume we are using quicksort to sort an array in ascending order. What can we conclude about the elements to the left of the currently placed pivot element?

(Multiple Choice)
4.8/5
(34)
Showing 101 - 109 of 109
close modal

Filters

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