Question: 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

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); }
1. array[lastIndex]
2. array[firstIndex]
3. array[lastIndex - 1]
4. array[firstIndex + 1]

2. Which of the following algorithms most naturally involve recursion?

I. Binary Search

II. Insertion Sort

III. Merge Sort

1. II and III only
2. II only
3. I and III only
4. I only

3. What is the best way to describe the complexity of the Insertion Sort algorithm?

1.Quadratic
2.Log-Linear
3.Constant time
4.Linear

4. What is the complexity of the Binary Search algorithm?

1. O(log n)
2. O(n)
3. O(n log n)
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

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!