logo

APSU Notes


Quiz 10

Question 1

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.

Question 2

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 3

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

False

Question 4

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 5

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

True

Question 6

The merge sort algorithm contains only one recursive call.

False

Question 7

What is a recursive method?

True

Question 8

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

True

Question 9

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.

Question 10

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.

Question 11

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

Only one branch may contain a recursive call.

Question 12

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

Notes

Quiz 6, Chapter 3/Recusion