CSCI 2010 - QUIZ 6 QUESTIONS AND VERIFIED
ANSWERS
Which of the following best describes the steps taken by the merge sort algorithm when
sorting the array containing the following numbers: 4 3 2 1. - Answers - 4 3 2 1
3421
3412
1234
Java treats a recursive method call differently from an ordinary method call. - Answers -
False
Which of the following best describes the binary search algorithm? - Answers - A sorted
array is searched starting in the middle. If the middle element is smaller than the search
item, the right half is searched recursively. If the middle element is larger than the
search item, the left half is searched recursively. The search continues until the search
item is found or no items are left.
Which of the following is *not* required for the correct implementation of a recursive
method? - Answers - Only one branch may contain a recursive call.
A recursive method must contain a base case, otherwise it will not terminate. - Answers
- True
For large arrays, binary search is much faster than sequential search. - Answers - True
The merge sort algorithm contains only one recursive call. - Answers - False
What is the output of the following code?
public static void main(String[] args)
{
System.out.println(getMysteryValue(3));
}
public static int getMysteryValue(int n)
{
if( n <= 1)
return 1;
else
return getMysteryValue(n - 1) + n;
} - Answers - 6
ANSWERS
Which of the following best describes the steps taken by the merge sort algorithm when
sorting the array containing the following numbers: 4 3 2 1. - Answers - 4 3 2 1
3421
3412
1234
Java treats a recursive method call differently from an ordinary method call. - Answers -
False
Which of the following best describes the binary search algorithm? - Answers - A sorted
array is searched starting in the middle. If the middle element is smaller than the search
item, the right half is searched recursively. If the middle element is larger than the
search item, the left half is searched recursively. The search continues until the search
item is found or no items are left.
Which of the following is *not* required for the correct implementation of a recursive
method? - Answers - Only one branch may contain a recursive call.
A recursive method must contain a base case, otherwise it will not terminate. - Answers
- True
For large arrays, binary search is much faster than sequential search. - Answers - True
The merge sort algorithm contains only one recursive call. - Answers - False
What is the output of the following code?
public static void main(String[] args)
{
System.out.println(getMysteryValue(3));
}
public static int getMysteryValue(int n)
{
if( n <= 1)
return 1;
else
return getMysteryValue(n - 1) + n;
} - Answers - 6