Self-assessment 06: Sample questions

The self-assessment will have four questions, and cover material through the end of the graphs and search topic.


In the first question, you will demonstrate your understanding of the behavior of the breadth-first search algorithm, similar to that in Problem Set 09 (reproduced here):

Suppose you have the following directed graph.

a graph

If you were to perform a breadth-first search to completely explore this graph, starting from S, in what order would the vertices be added to the frontier? Use the same BFS algorithm we covered in lecture and in programming assignment 10. Assume that the neighbors of each vertex are returned in alphabetical order. Do not stop the search if it finds a G node; completely explore the graph.


In the second and third questions, you will show you understand the LIFO behavior of stacks and/or the FIFO behavior of queues (be prepared for both). For example, a question might state:

Suppose you have an empty stack, and you execute the following operations:

push(1);
push(2);
push(3);
peek();
pop();
push(1);
pop();
pop();

What are the contents of the stack? Be sure to clearly indicate the top of the stack.


The final question will ask you to write one of the stack or queue operations that we covered in class.

For example, a question might state:

Suppose we have a singly linked-list-based implementation of a Stack<E>, built of Node<E> elements that link to one another.

The Node<E> class has a public Node<E> next and a public E data instance variable.

The Stack<E> has a head instance variable, pointing to the first Nodes of the list (or null if the list is empty), as well as an int size.

In other words, it is the implementation we wrote in lecture.

Write the void pop(E e) method.

Check your answers here.