Simple queue operations
=======================

``` {.java}
Queue<String> q = new Queue<String>();
q.enqueue("cardie");
q.enqueue("duncan");
String x = q.dequeue();
q.enqueue("ebony");
String y = q.dequeue();
q.enqueue(x);
System.out.println(q.dequeue());
```

What is printed?

a.  "cardie"
b.  "duncan"
c.  *"ebony"*
d.  an exception is thrown

Distance
========

    X-X--XXX---X*X-XXX-X--
    XXX--X--XXX-XXXX-XX---
    --XXXX-----XX-X-X-X---
    -----XX-----XX-XX*XX--
    ----XX-XXXX--XXX---XXX

What is the distance between the two stars?

a.  9
b.  *10* (down first, then right)
c.  11
d.  12

Breadth-first search
====================

Suppose we BFS from the `*`.

    X-X--XXX---X-XXXX--X--
    XXX--X--BXXA*X--X-----
    --XXXX-------XX-X-----
    -----XX--------XXXXC--
    ----XX-XXXX----X---XXX

Which square do we reach first?

a.  *A*
b.  B
c.  C
d.  it depends

Depth-first search
==================

Suppose we DFS from the `*`.

    X-X--XXX---X-XXXX--X--
    XXX--X--BXXA*X--X-----
    --XXXX-------XX-X-----
    -----XX--------XXXXC--
    ----XX-XXXX----X---XXX

Which square do we reach first?

a.  A
b.  B
c.  C
d.  *it depends* upon the order of neighbors explored

Changing enqueue
================

``` {.java}
public void enqueue(T element) {
  LLNode<T> node = new LLNode<T>(element);
  if (head == null) {
    head = newNode);
  } else {
    tail.setLink(newNode); }
  tail = tail.getLink();
}
```

We changed the last line. What's broken (if anything)?

a.  nothing breaks
b.  the old tail pointer now points to itself
c.  *there's a NPE if the queue was empty*
d.  the old tail node gets garbage collected
e.  enqueue shouldn't change the tail pointer

Queue size
==========

Elements in an array-backed queue start at `front` and proceed to
`rear`. Which gives the number of elements in a non-empty queue?

a.  `(rear - front) % capacity`
b.  `(rear - front + 1) % capacity`
c.  `(front - rear + 1) % capacity`
d.  *none of these* see lecture notes for a way to compute it

Big-O Doubling
==============

Growing an array x to size n using repeated incrementing by 100 costs
100 + 200 + 300 + ... + n.

Growing an array y to size n using repeated doubling costs 100 + 200 +
400 + ... + n.

What are the big-O expressions for these sums?

a.  O(n) for both
b.  O($n^2$) for both
c.  O(n) for x, O($n^2$) for y
d.  *O($n^2$) for x, O(n) for y*

