11.3. Preview Questions#
Complete these questions before class to prepare for the chapter. Use the dropdowns to check your answers.
11.3.1. True or False#
1. A stack follows Last-In, First-Out (LIFO) order.
Answer
True — The most recently pushed item is the first to be popped.
2. A queue follows Last-In, First-Out (LIFO) order.
Answer
False — A queue is First-In, First-Out (FIFO).
3. In C#, Stack<T>.Pop() removes and returns the top element.
Answer
True — Pop() both removes and returns the top item.
4. A linked list provides O(1) random access by index.
Answer
False — Linked list access by index is O(n); arrays provide O(1) access.
5. Queue<T>.Enqueue() adds an element to the back of the queue.
Answer
True — Elements enter at the back and leave from the front.
11.3.2. Multiple Choice#
1. Which data structure is best for implementing an ‘undo’ feature?
a) Queue
b) Stack
c) List
d) Dictionary
Answer
b) Stack — LIFO order means the last action is the first to be undone.
2. What does Queue<T>.Dequeue() do?
a) Adds to the back
b) Peeks at the front
c) Removes and returns the front element
d) Clears the queue
Answer
c) Removes and returns the front element — Dequeue() removes and returns the element at the front.
3. In a singly linked list, each node contains:
a) Only a value
b) Only a pointer
c) A value and a pointer to the next node
d) Two pointers
Answer
c) A value and a pointer to the next node — Each node stores data and a reference to the next node.
4. Which collection processes tasks in the order they arrive (FIFO)?
a) Stack
b) Dictionary
c) Queue
d) Array
Answer
c) Queue — Queue maintains arrival order — first in, first out.
5. What is the time complexity of inserting at the front of a linked list?
a) O(n)
b) O(log n)
c) O(1)
d) O(n²)
Answer
c) O(1) — Insertion at the head only updates one pointer, so it is O(1).
Footnotes