Quiz 06 sample questions

The quiz will have about three questions, and cover material on queues, implementations of queues, and recursion.


In the following method, (i) identify base case(s), (ii) identify the recursive case(s), and (iii) state whether it will always terminate normally, without throwing an exception. If (i) or (ii) are implicit, then note what they depend upon; or, if (i) or (ii) are missing, then note that fact.

Assume that in the first call to allEven(), currentIndex == 0.

public static boolean allEven(List<Integer> list, int currentIndex) {
    if (currentIndex == list.size()) {
        return true;
    }
    else if (list.get(currentIndex) % 2 == 1) {
        return false;
    }
    else {
        return allEven(list, currentIndex + 1);
    }
}

Suppose you have an empty queue of integers, and on that queue you execute the following operations:

  • add 3
  • add 1
  • add 2
  • remove
  • add 2
  • add 1
  • add 3
  • remove

Show the final contents of the queue. Clearly indicate the front and rear of the queue.


Suppose we have a singly linked-list-based implementation of a Queue<E>, built of Node<E> elements that link to one another. Further suppose it has head and tail instance variables, pointing to the first and last elements of the list, as well as an int size. In other words, it is the implementation we wrote in lecture.

(Be prepared to write any of its instance methods.)


You can check your answers here.