Previous QuizPrev Quiz
Sorting and Searching
Next QuizNext Quiz

Big Java Binder Early Objects

Computing

Quiz 14 :
Sorting and Searching

Quiz 14 :
Sorting and Searching

Showing 1 - 20 of 109
Next Quiz
arrow
What type of algorithm places elements in order?
Free
Multiple Choice
Answer:

Answer:

A

arrow
In each iteration, selection sort places which element in the correct location?
Free
Multiple Choice
Answer:

Answer:

B

arrow
After 5 iterations of selection sort working on an array of 10 elements, what must hold true?
Free
Multiple Choice
Answer:

Answer:

B

arrow
After one iteration of selection sort working on an array of 10 elements, what must hold true?
Multiple Choice
Answer:
arrow
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 loop condition to read i < a.length. What would be the result?
Multiple Choice
Answer:
arrow
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
Answer:
arrow
Consider the sort method for selection sort shown below: 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 loop control to read int i = 1; i < a.length - 1; i++. What would be the result?
Multiple Choice
Answer:
arrow
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
Answer:
arrow
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
Answer:
arrow
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
Answer:
arrow
After 9 iterations of selection sort working on an array of 10 elements, what must hold true?
Multiple Choice
Answer:
arrow
Which selection sort iteration guarantees the array is sorted for a 10-element array?
Multiple Choice
Answer:
arrow
The largestPosition method below returns the index of the largest element in the tail range of an array of integers. Select the expression that would be needed to complete the selectionSort method below, so that it sorts the elements in descending order. /** Finds the largest element in the tail range of an array. @param a the array to be searched @param from the first position in a to compare @return the position of the largest element in range a[from]..a[a.length - 1] */ Private static int largestPosition(int[] a, int from) { Int maxPos = from; For (int j = from + 1; j < a.length; j++) { If (a[j] > a[maxPos]) { MaxPos = j; } } Return maxPos; } Public static void selectionSort(int[] A) { For ____________________________________ { Int maxPos = largestPosition(a, i); ArrayUtil.swap(a, maxPos, i); } }
Multiple Choice
Answer:
arrow
The code segment below is designed to add the elements in an array of integers. Select the expression needed to complete the code segment so that it calculates the running time elapsed. long start = System.currentTimeMillis(); Int sum = 0; For (int k = 0; k < values.length; k++) { Sum = sum + values[k]; } Long runningTime = ____________________________;
Multiple Choice
Answer:
arrow
The performance of an algorithm is most closely related to what?
Multiple Choice
Answer:
arrow
Consider an array with n elements. If we visit each element n times, how many total visits will there be?
Multiple Choice
Answer:
arrow
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
Answer:
arrow
Suppose an algorithm requires a total of 3n3 + 2n2 - 3n + 4 visits. In big-Oh notation, the total number of visits is of what order?
Multiple Choice
Answer:
arrow
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
Answer:
arrow
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
Answer:
Showing 1 - 20 of 109
Next Quiz