Nathan Sprague
9/20/21
OpenDSA version:
public interface Queue<E> { // Queue class ADT
// Reinitialize queue
public void clear();
// Put element on rear
public boolean enqueue(E it);
// Remove and return element from front
public E dequeue();
// Return front element
public E frontValue();
// Return queue size
public int length();
//Tell if the queue is empty or not
public boolean isEmpty();
}What will be printed when this code executes:
Big-\(\Theta\) cost?
| operation | cost |
|---|---|
enqueue() |
|
dequeue() |
|
frontValue() |
|
length() |
Big-\(\Theta\) cost?
| operation | cost |
|---|---|
enqueue() |
\(\Theta(1)\)* |
dequeue() |
\(\Theta(1)\) |
frontValue() |
\(\Theta(1)\) |
length() |
\(\Theta(1)\) |
* Amortized
Which of the following describes the most reasonable organization of a linked queue?
enequeue and dequeue are performed at the head. There is no need to maintain a tail reference.
enequeue is performed at the tail. dequeue is performed at the head.
enequeue is performed at the head. dequeue is performed at the tail.
Both a head and tail reference are required, but it doesn’t matter which is used for enequeue and which is used for dequeue.
Big-\(\Theta\) cost?
| operation | cost |
|---|---|
enqueue() |
|
dequeue() |
|
frontValue() |
|
length() |
Big-\(\Theta\) cost?
| operation | cost |
|---|---|
enqueue() |
\(\Theta(1)\) |
dequeue() |
\(\Theta(1)\) |
frontValue() |
\(\Theta(1)\) |
length() |
\(\Theta(1)\) |