Exam 14: Sorting and Searching

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

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

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

(Multiple Choice)
4.7/5
(40)

A version of which sort algorithm is used in the sort method in the Java Arrays class?

(Multiple Choice)
4.8/5
(35)

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

Consider an array with n elements. If we visit each element n times, how many total visits will there be?

(Multiple Choice)
4.8/5
(37)

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

(Multiple Choice)
4.7/5
(28)

In big-Oh notation, when we consider the order of the number of visits an algorithm makes, what do we ignore? I power of two terms II the coefficients of the terms III all lower order terms

(Multiple Choice)
4.9/5
(41)

Consider the minimumPosition method from the SelectionSorter class. Complete the code to write a maximumPosition method that returns the index of the largest element in the range from index from to the end of the array. private static int minimumPosition(int[] a, int from) { Int minPos = from; For (int i = from + 1; i < a.length; i++) { If (a[i] < a[minPos]) { minPos = i; } } Return minPos; } Private static int maximumPosition(int[] a, int from) { Int maxPos = from; For (int i = from + 1; i < a.length; i++) { ________________ } Return maxPos; }

(Multiple Choice)
4.8/5
(35)

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

(Multiple Choice)
4.9/5
(34)

Assume that bands is an ArrayList of String objects which contains a number of elements in ascending order. Select a statement to complete the code segment below, which invokes the Java library binarySearch method to search for the string "Beatles". If the list does not already contain the string, it should be inserted in an appropriate location so that the list remains sorted. Int index = Collections.binarySearch(bands, "Beatles"); If (index < 0) { __________________________ }

(Multiple Choice)
4.9/5
(31)

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

(Multiple Choice)
4.8/5
(46)

If you increase the size of a dataset fivefold, how much longer does it take to sort it with the selection sort algorithm?

(Multiple Choice)
4.8/5
(47)

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

(Multiple Choice)
4.8/5
(32)

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

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

(Multiple Choice)
4.9/5
(34)

When your class implements a comparator object, you must implement the compare method. What must be true about the return value from this method when comparing two objects, a and b with a call to a.compare(b)?

(Multiple Choice)
4.8/5
(42)

Which notation, big-Oh, theta, or omega describes the growth rate of a function? I big-Oh II theta III omega

(Multiple Choice)
4.9/5
(40)

Binary search is an ____ algorithm.

(Multiple Choice)
4.9/5
(40)

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

(Multiple Choice)
4.9/5
(41)

Merge sort is a(n) ____ algorithm.

(Multiple Choice)
4.8/5
(43)
Showing 41 - 60 of 109
close modal

Filters

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