CS 0445 - Quiz #2
We can define the Towers of Hanoi solution in the following way:To move N disks from start to end we Recursively move N-1 disks from ____________________ to ____________________. Move 1 disk from start to end Recursively move N-1 disks from ___________________ to ___________________. For each blank, enter one of the values: start, middle, end.
start middle middle end
In the Towers of Hanoi solution, how many disks are actually moved in a single call to the method?
1
Consider an LList containing 5 items. We would like to "visit" all of the items in the list using calls to the getEntry(i) method. How many total nodes must be accessed in order to "visit" all of the items in this list?
15
Consider an array containing 100 items. If a random pivot is chosen for partition, what is the probability that the worst case for a single partition will occur (all items on one side or the other of the pivot)? Give your answer as a whole number to represent a percentage (ex: 10 would mean there is a 10% chance).
2
In the Towers of Hanoi solution with N = 5, how many total moves must be performed?
31
Consider the following Java method: public void Foo(int N) { if (N >= 2) { Foo(N/2); Foo(N/2); } } How many total calls to Foo will occur with the initial call: Foo(4); Don't forget the initial call in your total.
7
Two important ideas implemented in languages such as Java that allow recursion to work are _________________________ (two words -- where the local data and parameters are stored) and the run-time ______________________ (where the answer to the first blank is placed)
Activation record Stack
Consider the value N = 2^k for some integer K. What is another representation of N/2? a. 2^(k/2) b. 2^k - 2 c. 2^k - 1 d. 2^(k-1)
d. 2^(k-1)
In the FindWord problem, if we succeed in finding a string at some position in the board, why might we still want to backtrack / continue the search?
To find more than one solution
In our ResizableArrayBag<T>, If we start our array size at 1, and double the array size each time we need more space, which of the following adds() will require a resize (assuming add 1 is our first add()). Indicate all adds where a resize is necessary. a. 2 b. 3 c. 4 d. 5 e. 6
a. 2 b. 3 d. 5
Comparison based sorting has a lower bound of NlgN. What does this statement mean? a. Any comparison based sorting algorithm has a run-time of at least NlgN. b. Any comparison based sorting algorithm has a run-time of at most NlgN. c. It is possible to write a program to sort data that takes NlgN time. d. It is not possible to write a program to sort data that takes NlgN time.
a. Any comparison based sorting algorithm has a run-time of at least NlgN.
Given our overall discussion of QuickSort and MergeSort, for which of the following data types might I prefer MergeSort to QuickSort? Select all that apply. a. Class People from the course handouts b. Class String c. long d. Class Worker from the course handouts
a. Class People from the course handouts d. Class Worker from the course handouts
Consider a ListInterface<T> variable, L, which could be assigned to either an AList (array list) or an LList (linked list). Indicate each operation below for which the the AList will be asymptotically better than the LList. [Note 1: to get credit for this question you must select ALL correct answers] a. L.getEntry(i) in the average case b. L.add(1¸ newEntry) c. L.add(L.getLength()+1¸ newEntry) d. L.add(k¸ newEntry) for arbitrary k in the worst case
a. L.getEntry(i) in the average case c. L.add(L.getLength()+1¸ newEntry)
What does the following expression evaluate to? 2^(log2N) a. N b. NLog2N c. N^2 d. 2^N
a. N
In amortized time, assuming that the array size is doubled each time we resize, how much time does an add() require in a ResizableArrayBag<T>? a. O(1) b. O(Log2N) c. O(N) d. O(N^2)
a. O(1)
When we backtrack from call K to call K-1 in our 8-Queens solution, what do we do next? a. Remove the queen from its current row in column K-1 b. Make a new recursive call to column K+1 c. Backtrack to column K-2
a. Remove the queen from its current row in column K-1
Consider the SimpleDeque<T> implementation from Recitation Exercise 1, and consider the addToFront() method and the removeBack() method. Which statement below is FALSE? a. The addToFront() operation is O(1) b. The removeBack() operation is O(1) c. The amortized time per operation for N addToFront() operations followed by N removeBack() operations is O(N)
a. The addToFront() operation is O(1)
At the end of the partition algorithm in QuickSort, which of the following are known to be true? [Note: In order to get credit for this question you must indicate ALL true statements below]. a. The pivot value is in its final correct location within the array b. The values on the "left" side of the array are all less than the pivot c. The values on the "right" side of the array are all greater than or equal to the pivot d. The "left" and "right" sides of the array are the same size (plus or minus 1)
a. The pivot value is in its final correct location within the array c. The values on the "right" side of the array are all greater than or equal to the pivot
Which of the following are true about a solution to the 8-Queens problem? Indicate all true answers. a. There is exactly 1 queen in each column of the board b. There is exactly 1 queen in each row of the board c. There is exactly 1 queen in each diagonal of the board
a. There is exactly 1 queen in each column of the board b. There is exactly 1 queen in each row of the board
Consider the QuickSort algorithm as discussed in lecture. When are the data comparisons done in this algorithm? a. While the data is being "divided", prior to the recursive calls. b. While the data is being "put back together", after the recursive calls. c. Both before and after the recursive calls.
a. While the data is being "divided", prior to the recursive calls.
If I have a list of N items in locations from 1 to N and selecting any of them is equally likely, what is the probability of selecting an arbitrary item i? a. i/N b. 1/N c. N/2 d. N e. N(N+1)/2
b. 1/N
Consider the recursive cases for the Power function below. Which is a good divide and conquer solution from a programming point of view? [Note: The definitions do not have to be complete here] 1. Power(X, N) = (Power(X, N/2)(Power(X, N/2)) 2. Power(X, N) = (Power(X, N/2))^2 3. Power(X, N) = (X)(Power(X, N-1)) a. 1. only is good b. 2. only is good c. 1 and 2 only are good d. All of 1, 2, 3 are good e. None of them are good
b. 2. only is good
Consider ShellSort and specifically the last iteration of the outer loop. What is happening in this iteration of the outer loop? a. A K-Insertionsort is being done where K = N/2 b. A "full" InsertionSort is being done c. A SelectionSort is being done
b. A "full" InsertionSort is being done
Consider some iterator, iter, which was created on a list of Integer. Consider the code below: while (true) { Integer X = iter.next(); System.out.println("Next value is " + X); } What will happen if this code segment is executed? a. All of the values in the list will be printed, followed by an infinite number of null values b. All of the values in the list will be printed, followed by an Exception c. The code segment will immediately throw an Exception d. The code segment will not compile
b. All of the values in the list will be printed, followed by an Exception
When a backtracking algorithm "backtracks", what is happening in the execution? a. A new activation record is being pushed onto the run-time stack b. An activation record is being popped off of the run-time stack c. Execution continues using the same activation record d. A loop iterates
b. An activation record is being popped off of the run-time stack
Consider the getEntry(i) method in ListInterface, and a list containing N items. What is the worst case asymptotic run-time for getEntry(i) for an array list and for a linked list? a. Array list O(1), Linked list O(1) b. Array list O(1), Linked list O(N) c. Array list O(N), Linked list O(1) d. Array list O(N), Linked list O(N)
b. Array list O(1), Linked list O(N)
Given that the last iteration of the outer loop of ShellSort is a full InsertionSort, and given that there are several (many) iterations of the outer loop of ShellSort prior to the full InsertionSort, how does ShellSort have a better run-time than InsertionSort? a. The premise is incorrect -- ShellSort does not have a better run-time than InsertionSort. b. By the time ShellSort gets to the last iteration of the outer loop, the data is close to being sorted, which is the best case for InsertionSort. c. Magic
b. By the time ShellSort gets to the last iteration of the outer loop, the data is close to being sorted, which is the best case for InsertionSort.
In ShellSort, the last iteration of the outer loop a. Has nothing left to do since the data is sorted by this point b. Does a full InsertionSort of the data c. InsertionSorts the data that are N/2 locations apart in the array d. SelectionSorts the remaining items in the array
b. Does a full InsertionSort of the data
Select the most appropriate statement below. a. Integer multiplication is a constant time operation b. Integer multiplication is not a constant time operation, but int and long multiplication are constant due to their fixed bit lengths c. Multiplying two Java long numbers that are very large in value will take more time than multiplying two Java long numbers that are small in value.
b. Integer multiplication is not a constant time operation, but int and long multiplication are constant due to their fixed bit lengths
We determined the average (expected) case for getEntry(i) in an LList<T> to be (N+1)/2 node accesses. How does this compare to the worst case of N node accesses? a. It is asymptotically better b. It is better in actual value but not an asymptotic improvement c. It is not better in any way
b. It is better in actual value but not an asymptotic improvement
Consider the simple QuickSort algorithm discussed in lecture (rightmost element chosen as the pivot). Assume that the data is sorted prior to the call of QuickSort. Will this end up being a good or a bad case for the algorithm? a. It will yield best case behavior b. It will yield worst case behavior c. It will yield good but not best case behavior d. It will yield poor but not worst case behavior
b. It will yield worst case behavior
Consider the run-time analysis of MergeSort vs. the Towers of Hanoi. Both have tree execution traces, but the overall run-times are very different. Consider a single call of size N for each algorithm. How much work is needed at this call itself and what is the size of the subproblems generated for each algorithm? The answers are shown as pairs: work at the call, size of subproblems. a. MergeSort: O(1), N/2____Towers of Hanoi: O(1), N-1 b. MergeSort: O(N), N/2____Towers of Hanoi: O(1), N-1 c. MergeSort: O(1), N/2____Towers of Hanoi: O(N), N-1 d. MergeSort: O(N), N/2____Towers of Hanoi: O(N), N-1 e. MergeSort: O(N), N/2____Towers of Hanoi: O(N), N/2
b. MergeSort: O(N), N/2____Towers of Hanoi: O(1), N-1
Does RadixSort sort in place? a. Yes b. No
b. No
We know MergeSort has an asymptotic run-time of O(NlgN). This was informally determined by noting that the MergeSort execution tree has a. O(N) levels, each requiring O(lgN) work b. O(lgN) levels, each requiring O(N) work c. O(N) levels, each requiring O(N) work d. O(lgN) levels, each requiring O(lgN) work
b. O(lgN) levels, each requiring O(N) work
Consider the Java code segment below: int curr = N; int ans = 0; while (curr > 0) { ans++; curr = curr / 2; } System.out.println("Ans is " + ans); What is the asymptotic runtime of this code segment? a. O(N) b. O(log2N) c. O(NLog2N) d. O(N^2)
b. O(log2N)
What does each recursive call represent in our 8-Queens problem solution? a. Placing a queen at some column within a given row of the board b. Placing a queen at some row within a given column of the board c. Placing all of the queens on the board
b. Placing a queen at some row within a given column of the board
Logically, the "bins" that are used in RadixSort are a. Stacks b. Queues c. Bags d. Lists
b. Queues
If sorting an array of int in Java, which would you prefer [Note: To get credit for this problem you must indicate ALL correct answers] a. MergeSort because it is faster in actual run-time b. QuickSort because it is faster in actual run-time c. MergeSort because it is stable and QuickSort is not d. QuickSort because it is stable and MergeSort is not
b. QuickSort because it is faster in actual run-time
We know that with the simple pivot (rightmost item) QuickSort, a worst case is when the data is sorted prior to the sort. If rather than the rightmost item for the pivot, we instead use the leftmost item as the pivot, how will the QuickSort run-time be affected? a. It will make sorted data into a best case rather than a worst case b. Sorted data will still be a worst case for the algorithm c. Sorted data will not be the best cast but it will no longer be the worst case
b. Sorted data will still be a worst case for the algorithm
In our FindWord solution (to find Strings in a 2-d grid of characters), if we start at position (row, col) in the grid and we have been unsuccessful at finding the String in all directions, what does this mean? a. The String is not in the grid - there is not solution b. The String is not found starting at position (row, col) but could be somewhere else
b. The String is not found starting at position (row, col) but could be somewhere else
Consider InsertionSort of a linked list. What is the worst case scenario for this sort? a. The data is initially random. b. The data is initially sorted in order. c. The data is initially reverse sorted. d. All scenarios for this algorithm are the same.
b. The data is initially sorted in order.
The worst case situation for InsertionSort of an array occurs when a. The data is already sorted b. The data is reverse sorted c. The data is randomly distributed d. All cases for InsertionSort have the same behavior
b. The data is reverse sorted
Consider InsertionSort and the "sorted side" vs. the "unsorted side" of the array. What best describes the data on the "sorted side" of the array in InsertionSort? a. The data is sorted in an absolute way -- each item at location k will stay at location k for the rest of the sort. b. The data is sorted in a relative way -- the data is sorted but it could still move as more items are "inserted". c. The data is not actually sorted at all -- that term is incorrect.
b. The data is sorted in a relative way -- the data is sorted but it could still move as more items are "inserted".
In the recursive sequential search of an array, how is the problem size reduced with each recursive call? a. A new, smaller array is passed as an argument to the recursive call b. The front index is incremented by one and passed to the recursive call c. The back index is decremented by one and passed to the recursive call d. The front value will be set to equal (mid+1) and passed to the recursive call
b. The front index is incremented by one and passed to the recursive call
RadixSort has a run-time of O(KN). What does K represent? a. The number of distinct values in the alphabet / character set b. The maximum number of characters / digits in any one key c. The total number of keys being sorted d. The number of Queues needed during the sorting process
b. The maximum number of characters / digits in any one key
Consider RadixSort and two arrays of N Strings. Array A has Strings with maximum length 5 and array B has Strings with maximum length 10. How would the actual run-times of RadixSort on array A and array B compare? a. The run-times for the two arrays should be approximately the same. b. The run-time for array B should be about a factor of 2 longer than the run-time for array A c. the run-time for array A
b. The run-time for array B should be about a factor of 2 longer than the run-time for array A
Consider the following recursive case for the divide and conquer power function, pow(N): int recAns = pow(N/2); return (recAns*recAns); Which of the statements below is correct? a. This recursive case is always incorrect b. This recursive case is correct when N is even but incorrect when N is odd c. This recursive case is always correct
b. This recursive case is correct when N is even but incorrect when N is odd
Consider the 8-Queens problem as discussed in lecture (with indices from 0 to 7). If a queen CANNOT be placed in row 6 of column k, the algorithm will a. Try to place a queen in row 5 of column k b. Try to place a queen in row 7 of column k c. Try to place a queen in row 0 of column k+1 d. Backtrack to column k-1 and resume in the next row there
b. Try to place a queen in row 7 of column k
Consider the following code in the findWord method discussed in lecture: answer = findWord(r, c+1, word, loc+1, bo); if (!answer) answer = findWord(r+1, c, word, loc+1, bo); // more lines not shown Explain the purpose of the if statement prior to the second call of findWord() a. The second call will not typically be needed b. We only try the next direction if we did not succeed in the previous direction c. It is an error -- the "if" statement should not be there
b. We only try the next direction if we did not succeed in the previous direction
In our maze problem, when do we backtrack? a. When we want to change our direction moving forward b. When we can no longer move forward at all c. When we get to the maze exit
b. When we can no longer move forward at all
Consider the MergeSort algorithm as discussed in lecture. When are the data comparisons done in this algorithm? a. While the data is being "divided", prior to the recursive calls. b. While the data is being "put back together", after the recursive calls. c. Both before and after the recursive calls.
b. While the data is being "put back together", after the recursive calls.
Consider a list, L, containing (in order): 10, 20, 30Now consider the following code segment: Iterator<Integer> one = L.iterator(); Iterator<Integer> two = L.iterator(); Integer X = one.next(); Integer Y = two.next(); What are the values X and Y? a. X = 10, Y = 20 b. X = 10, Y = 10 c. X = 20, Y = 20
b. X = 10, Y = 10
Consider the MergeSort algorithm as discussed in lecture. At what point in the algorithm are the data actually compared to each other? a. As the data are being divided before the recursive calls b. In between the two recursive calls c. After both recursive calls have completed d. MergeSort is not a comparison-based sorting algorithm
c. After both recursive calls have completed
Consider standard Java List, L, of Integer containing 10, 20, 30 (in that order). What will be the effect of the code segment below? Iterator<Integer> one = L.iterator(); Iterator<Integer> two = L.iterator(); Integer X = one.next(); one.remove(); Integer Y = two.next(); a. X will be 10 and Y will be 10 b. X will be 10 and Y will be 20 c. An Exception will occur d. The code will not compile
c. An Exception will occur
Why might we use a base case other than 1 for QuickSort? a. A base case of 1 is actually invalid and we should never use that. b. As the problem sizes get smaller, the benefit of a divide and conquer approach increases. c. As the problem sizes get smaller, the benefit of a divide and conquer approach decreases.
c. As the problem sizes get smaller, the benefit of a divide and conquer approach decreases.
How does RadixSort handle Strings of different lengths? a. Nothing special needs to be done b. It "pads" shorter Strings on the LEFT with characters that come before 'A' in the ASCII set c. It "pads" shorter Strings on the RIGHT with characters that come before 'A' in the ASCII set
c. It "pads" shorter Strings on the RIGHT with characters that come before 'A' in the ASCII set
MergeSort does not sort in place and the author's code required a 2nd temporary array for the merge algorithm. How does this use of a temporary array affect the run-time of MergeSort? a. It degrades the asymptotic run-time of MergeSort and the empirical run-time of MergeSort b. It degrades the asymptotic run-time of MergeSort but it does not affect the empirical run-time of MergeSort c. It does not affect the asymptotic run-time of MergeSort but it degrades the empirical run-time of MergeSort d. It does not affect either the asymptotic run-time or the empirical run-time of MergeSort
c. It does not affect the asymptotic run-time of MergeSort but it degrades the empirical run-time of MergeSort
Consider SelectionSort and the item at location N-1 in the array (where the array is indexed from 0 to N-1). How is this item "selected" to be part of the sorted array? a. It is compared to the N-1 other items and put into its correct location. b. It is compared to its neighbor since that is the only item it could be switched with at this point in the algorithm c. It is not compared at all -- by the time we get to this item it is in the correct location by default.
c. It is not compared at all -- by the time we get to this item it is in the correct location by default.
Consider the Java code segment for base cases in the recursive sequential search of an array, A: // found if (A[front].equals(key) return front; // not found else if (front >= A.length) return -1; What, if anything, is wrong with this code? a. Nothing is wrong -- it is fine. b. The base case expression is incorrect c. It may cause an exception
c. It may cause an exception
Which of the following data scenarios CANNOT be the case after both recursive calls have completed in MergeSort (prior to actually merging)? Indicate all scenarios that CANNOT be the case. a. Left: 10 30 50 70 Right: 20 40 60 80 b. Left: 10 20 30 40 Right: 50 60 70 80 c. Left: 10 30 20 40 Right: 50 70 60 80 d. Left: 50 60 70 80 Right: 10 20 30 40
c. Left: 10 30 20 40 Right: 50 70 60 80
What is our basic approach to implementing the Iterator<T> interface in the LList<T> class? a. Put the Iterator methods directly into the LList<T> class b. Make the Iterator implementation a separate public class that accesses the LList<T> class c. Make the Iterator implementation a private inner class within LList<T>
c. Make the Iterator implementation a private inner class within LList<T>
Assume that we have a SimpleDeque<T> object that we have filled with N items. We will now call removeFront() until the deque is empty. How many total individual data assignments will need to be done in order to empty the deque in this way? a. N b. N^2 c. N(N+1)/2 d. 2N e. NLog2N
c. N(N+1)/2
Consider the sum: 1 + 2 + 3 + ... + N. Precisely what does this evaluate to in terms of N? a. 2N b. N^2 c. N(N+1)/2 d. N(N-1)/2
c. N(N+1)/2
What is the precise evaluation of the sum below? 1 + 2 + 3 + ... + N a. 2N b. N^2 c. N(N+1)/2 d. N(N-1)/2
c. N(N+1)/2
Consider a problem of size N. Which of the following subproblem sizes demonstrate a divide and conquer approach. Indicate all correct answers. a. N-1 b. N-2 c. N/2 d. N/4
c. N/2 d. N/4
Select the correct statement below. a. Recursive binary search and iterative binary search proceed through the data in equivalent, but very different ways. b. Recursive binary search and iterative binary search proceed through the data in similar, but not identical ways. c. Recursive binary search and iterative binary search proceed through the data in identical ways, always comparing the same values.
c. Recursive binary search and iterative binary search proceed through the data in identical ways, always comparing the same values.
Consider the iterative and recursive algorithms for sequential search of a linked list. Which statement below is true? a. The iterative algorithm is asymptotically superior to the recursive algorithm b. The recursive algorithm is asymptotically superior to the iterative algorithm c. The algorithms are asymptotically the same, but the iterative algorithm has less overhead d. The algorithms are asymptotically the same, but the recursive algorithm has less overhead
c. The algorithms are asymptotically the same, but the iterative algorithm has less overhead
Consider the author's ListInterface<T> and specifically the getEntry(i) method. Also consider the AList<T> and LList<T> classes. Which answer below is correct? a. The getEntry(i) method has an O(N) worst-case run-time in both implementations because we must do sequential search in each case b. The getEntry(i) method has an O(1) worst-case run-time in both implementations because both can access location i directly. c. The getEntry(i) method has an O(1) worst-case run-time for the AList<T> but an O(N) worst-case run-time for the LList<T> d. The getEntry(i) method has an O(1) worst-case run-time for the LList<T> but an O(N) worst-case run-time for the AList<T>
c. The getEntry(i) method has an O(1) worst-case run-time for the AList<T> but an O(N) worst-case run-time for the LList<T>
Assume you are in the last iteration of the outer loop for InsertionSort. Which statement below is correct? a. The last remaining item goes at the end of the array and no comparisons are needed b. The last remaining item must be moved all the way to the front of the array and N-1 comparisons are needed c. The last remaining item could end up in any position within the array.
c. The last remaining item could end up in any position within the array.
Consider recursive sequential search of an array, A, as discussed in lecture. In the code there are two base cases, as shown below: if (first >= A.length) return -1; else if (A[first].compareTo(key) == 0) return first; What would happen if the order of these base cases were reversed? a. The program would still be correct -- the order of these tests does not matter b. The program would have a compilation error c. The program would compile and might execute correctly, but it might crash with an exception d. The program would compile but would always crash with an exception
c. The program would compile and might execute correctly, but it might crash with an exception
We know the two "steps" in a divide and conquer solution are: 1) How do we break up the problem prior to the recursive call(s)? 2) How do we use the recursive results to get the overall result? How can step 2) best be described for Binary Search? a. We use the recursive answer to determine which half of the array to search next b. We use the recursive answer to eliminate one side of the array c. The recursive answer IS the answer -- we simply pass it on
c. The recursive answer IS the answer -- we simply pass it on
Consider the following Java code segment below, where L is a reference to some implementation of a standard Java List<Integer>. Iterator<Integer> iter = L.iterator(); while (iter.hasNext()) { Integer X = iter.next(); System.out.println("Next value is " + X); } Consider now two objects that may be stored in variable L: 1) An ArrayList<Integer> 2) A LinkedList<Integer> How will the run-time of the code differ with the two different objects? a. The ArrayList object will be asymptotically better than the LinkedList object b. The LinkedList object will be asymptotically better than the ArrayList object c. The run-times will be similar for both objects
c. The run-times will be similar for both objects
When using the median of three partition algorithm, what is guaranteed in each partition? a. The data will be split evenly between the left and right sides b. The difference between the number of items on the left side and the number of items on the right side will be at most N/4 c. There will be at least one item on the left side and at least one item on the right side
c. There will be at least one item on the left side and at least one item on the right side
Consider ListIterator<T> interface. How could we efficiently implement this interface with a singly linked list? a. Have a first and a last reference in the ListIterator<T> object. b. Have a curr and a prev reference in the ListIterator<T> object c. We cannot efficiently implement ListIterator<T> with a singly linked list
c. We cannot efficiently implement ListIterator<T> with a singly linked list
In the findWord() method that was discussed, in a given call we store the current location, loc, that we are trying to match within the goal string (i.e. we want board[r][c] == word.charAt(loc) to be true). When a call to findWord() backtracks, how do we update the value of loc to go back to its previous value (i.e. one index smaller)? a. We decrement loc so that it is assigned a smaller value (ex: loc = loc - 1). b. We have a list of loc values stored and access the previous one, which should have the previous value c. When the previous call resumes the value of loc in its activation record is the value that we want
c. When the previous call resumes the value of loc in its activation record is the value that we want
Which of the following is not a method in Iterator<T>? a. hasNext() b. next() c. add() d. remove()
c. add()
Consider the best case scenario for the QuickSort algorithm. In this scenario, how does each call to partition divide the data? Choose the best answer. a. N-1 items <= the pivot and 0 items greater than the pivot b. N-1 items >= the pivot and 0 items less than the pivot c. ~N/2 items <= the pivot and ~N/2 items >= the pivot d. Either A or B above
c. ~N/2 items <= the pivot and ~N/2 items >= the pivot
Consider the last iteration of the outer loop of InsertionSort. How many comparisons must be done for this iteration? a. No comparisons are required -- the last item is in its correct location by default. b. Only 1 comparison is needed -- it may have to swap with its neighbor but that is all. c. N-1 comparisons are needed -- it must be compared to all of the other items in the array d. It could be from 1 to N-1 comparisons, depending upon where the item will end up in the array.
d. It could be from 1 to N-1 comparisons, depending upon where the item will end up in the array.
Which of the following statements if FALSE? a. The Median of 3 version of QuickSort guarantees at least one value on each "side" of the pivot for each partition. b. The Median of 3 version of QuickSort will have the best case performance when the data is already sorted c. The Median of 3 version of QuickSort will have a worst case run-time of O(N^2) d. The Median of 3 version of QuickSort will have the worst case performance when the array is reverse sorted.
d. The Median of 3 version of QuickSort will have the worst case performance when the array is reverse sorted.
Consider the recursive methods for factorial, (simple) integer powers and sequential search. Give the most appropriate answer below. a. The recursive versions of these methods are preferable to the iterative versions because the recursive versions are asymptotically faster. b. The recursive versions of these methods are preferable to the iterative versions because the recursive versions have less overhead in their execution. c. The iterative versions of these methods are preferable to the recursive versions because the iterative versions are asymptotically faster. d. The iterative versions of these methods are preferable to the recursive versions because the iterative versions have less overhead.
d. The iterative versions of these methods are preferable to the recursive versions because the iterative versions have less overhead.
What is the worst case scenario for the initial state of the data in SelectionSort? a. The data is random b. The data is sorted in order c. The data is reverse sorted d. There is no worst case scenario -- all cases for SelectionSort require the same number of comparisons.
d. There is no worst case scenario -- all cases for SelectionSort require the same number of comparisons.