1. Consider the helper method reversePrint, which uses recursion to display in reverse the elements in a section of an array limited by the firstIndex and lastIndexarguments. What statement should be used to complete the recursive method?
public static void reversePrint(int[] array, int firstIndex, int lastIndex) { if (firstIndex < lastIndex) { reversePrint(array, firstIndex + 1, lastIndex); } System.out.println(_________________); } public static void main(String[] args) { int [] numbers = { 4, 7, 1, 0, 2, 7 }; reversePrint(numbers, 0, numbers.length - 1); }
2. Which of the following algorithms most naturally involve recursion?
I. Binary Search
II. Insertion Sort
III. Merge Sort
3. What is the best way to describe the complexity of the Insertion Sort algorithm?
4. What is the complexity of the Binary Search algorithm?
4. | O(n^2) [ Note: n^2 means n-squared ] |
5. Which of the following is most true about algorithm complexity, assuming large tasks?
1. | Linear-time algorithms are faster than both exponential-time and logarithmic-time algorithms |
2. | An algorithm of complexity O(n^5) is considered more complex (taking more time) than an algorithm of complexity O(5^n) |
3. | Exponential-time algorithms are generally practical while polynomial-time algorithms are typically not practical |
4. | Polynomial-time algorithms are generally practical while exponential-time algorithms are typically not practical |