Exam 14: Sorting and Searching

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

A portion of your program includes the loops shown in the code snippet below to examine the elements of two arrays, arr1 and arr2, both of length n: Int matches = 0; For (int i = 0; i < arr1.length; i++) { For (int j = 0; j < arr2.length; j++) { If (arr1[i].equals(arr2[j])) { Matches++; } } } What can you conclude about the running time of this section of code?

(Multiple Choice)
4.8/5
(24)

Can you search the following array using binary search? Int[] A = {6, 5, 4, 2, 0, 1, -1, -17};

(Multiple Choice)
4.8/5
(41)

A portion of your program includes the method shown in the code snippet below to examine the elements of an array arr: Private int findElement(int[] arr, int newVal) { Int pos = Arrays.binarySearch(arr, newVal); Return pos; } What can you conclude about the running time of this section of code?

(Multiple Choice)
4.7/5
(38)

The binarySearch method of the Collections class returns a value in the form of -k - 1 when the target item you are searching for was not found in the array. What does k represent?

(Multiple Choice)
4.7/5
(28)

What type of algorithm places elements in order?

(Multiple Choice)
4.9/5
(41)

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

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 call to the swap method call to read swap(i, minPos). What would be the result?

(Multiple Choice)
4.9/5
(32)

How many times can an array with 729 elements be cut into three equal pieces?

(Multiple Choice)
4.9/5
(33)

If you implement a recursive linear search, its performance will be ____.

(Multiple Choice)
4.7/5
(41)

Which of the following statements about running times of algorithms is correct?

(Multiple Choice)
4.8/5
(29)

Given the following code snippet for searching an array: Int[] arr = {23, 25, 29, 34, 42}; Int newVal = 15; Int pos = Arrays.binarySearch(arr, newVal); What value will pos have when this code is executed?

(Multiple Choice)
4.7/5
(33)

Find the simplest order of growth of the following expression: (n3 + n + 3)2.

(Multiple Choice)
4.8/5
(38)

How many comparisons does selection sort make when sorting an array of length n?

(Multiple Choice)
4.8/5
(34)

Choose the order of the following growth rates, from slowest to fastest: θ(n3), θ(nlog(n)), θ(n3/2), θ(2n).

(Multiple Choice)
4.9/5
(39)

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?

(Multiple Choice)
4.9/5
(44)

Assume we are using quicksort to sort an array in ascending order. Into which array location does quicksort's strategy place a pivot element after partitioning?

(Multiple Choice)
4.9/5
(43)

If f(n) = O(g(n)) and g(n) = O(f(n)), what else must be true? I f(n) = Ω(g(n)) II g(n) = Ω(f(n)) III f(n) = θ(g(n))

(Multiple Choice)
4.9/5
(35)

Which of the sorts in the textbook can be characterized by the fact that even in the worst case the running time will be O(n log(n)))? I quicksort II selection sort III merge sort

(Multiple Choice)
4.8/5
(46)

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

(Multiple Choice)
4.8/5
(39)

Merge sort is a(n) ____ algorithm.

(Multiple Choice)
4.7/5
(40)
Showing 21 - 40 of 99
close modal

Filters

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