logo

APSU Notes


Quiz 6

Question 1

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

Question 2

Java treats a recursive method call differently from an ordinary method call.

False

Question 3

Which of the following best 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.

Question 4

Which of the following is not required for the correct implementation of a recursive method?

Only one branch may contain a recursive call.

Question 5

A recursive method must contain a base case, otherwise it will not terminate.

True

Question 6

For large arrays, binary search is much faster than sequential search.

True

Question 7

The merge sort algorithm contains only one recursive call.

False

Question 8:

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

Question 9

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

Question 10

When does a stack overflow occur?

When the data structure used to keep track of recursive calls becomes to large to be stored in available memory.

Question 11

What is a recursive method?

A method that calls itself

Question 12

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.

Notes

Quiz 10, Chapter 3/Recusion