Which of the following describes the binary search algorithm?
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 best describes the steps taken by the merge sort algorithm when sorting the array containing the following numbers: 4 3 2 1.
1 2 3 4 4 3 2 1 3 4 2 1 3 4 1 2 1 2 3 4
Java treats a recursive method call differently from an ordinary method call.
False
What is the output of the following code?
1
2
3
4
5
6
7
8
9
10
11
public static void main(String[] args)
{
System.out.println(getMysteryValue(3));
}
pubic static int getMysteryValue(int n)
{
if (n <= 1)
return 1;
else
return getMysteryValue(n - 1) + n;
}
6
For large arrays, binary search is much faster than sequential search.
True
The merge sort algorithm contains only one recursive call.
False
What is a recursive method?
True
A recursive method must contain a base case, otherwise it will not terminate.
True
Which of the following best describes the merge sort algorithm?
The array is split in half, the two halves are sorted recursively, then the two halves are combined to put all items in the correct order.
When does a stack overflow occur?
AWhen the data structure used to keep track of recursive calls becomes to large to be stored in available memory.
Which of the following is not required for the correct implementation of a recursive method?
Only one branch may contain a recursive call.
Given an sorted array containing the following numbers: 1 3 7 10 12 17 19, what numbers are compared with the search item by a binary search for the number 12?
10, 17, 12