6 Quizzes • 8 MCQs Each • Spring 2026
For Rolf to review — flag any questions to change
| Quiz | Topics | Week | Approx. Date | RCT Groups |
|---|---|---|---|---|
| Quiz 1 | Arrays + Big-O + Linked Lists | 5 | Feb 10–14 | X + Y |
| Quiz 2 | Recursion | 7 | Feb 24–28 | X + Y |
| Quiz 3 | Stacks + Queues | 9 | Mar 10–14 | X + Y |
| Quiz 4 | Trees + Priority Queues | 11 | Mar 24–28 | X + Y |
| Quiz 5 | Heaps + Hash Tables/Maps | 13 | Apr 7–11 | X + Y |
| Quiz 6 | Search Trees + Dynamic Programming | 14–15 | Apr 14–18 | X + Y |
Format: 8 MCQs per quiz (4 per topic), ~12 minutes, taken in class on phones/laptops. Both sections take the identical quiz.
8 questions (3 Arrays, 2 Big-O, 3 Linked Lists)
Answer: B — int[] arr = new int[10];
Square brackets on the type (int[]), allocated with new and size in brackets. Option A uses parentheses. Option C is missing 'new'.
Answer: C
Dynamic arrays typically double capacity when full. All elements are copied — O(n) operation, amortized O(1).
Answer: C — O(n)
Inserting at index 0 requires shifting all n elements one position right. Arrays are poor for front insertions — linked lists handle this in O(1).
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
System.out.println(i + j);
}
}
Answer: C — O(n²)
Outer loop runs n times × inner loop runs n times = n² total iterations.
int[] doubleArray(int[] arr) {
int[] result = new int[arr.length];
for (int i = 0; i < arr.length; i++) {
result[i] = arr[i] * 2;
}
return result;
}
Answer: C — O(n)
Allocates a new array of size n. The loop variable is O(1) extra. Total additional space: O(n).
Answer: B — Set B.next = D
To remove C, bypass it by pointing its predecessor (B) to its successor (D). This is why deletion in a singly linked list requires access to the previous node.
Answer: C
Inserting at the front of a linked list is O(1) — just create a new node and point it to the old head. Arrays require shifting all elements. Arrays win on index access, memory density, and cache performance.
Answer: C
Removing the last element requires updating the second-to-last node's next pointer. In a doubly linked list, tail.prev gives you that node in O(1). A singly linked list must traverse the entire list to find it.
8 questions (all Recursion)
int f(int n) {
if (n == 0) return 0;
return n + f(n - 1);
}
Answer: C — 10
f(4) = 4 + f(3) = 4 + 3 + f(2) = 4 + 3 + 2 + f(1) = 4 + 3 + 2 + 1 + f(0) = 4+3+2+1+0 = 10. This computes the sum 1+2+...+n.
int factorial(int n) {
if (n <= 1) return 1;
return n * factorial(n - 1);
}
Answer: C — 120
factorial(5) = 5 × 4 × 3 × 2 × 1 = 120.
void countdown(int n) {
System.out.println(n);
countdown(n - 1);
}
Answer: D — StackOverflowError
There is no base case to stop the recursion. The method keeps calling itself forever (5, 4, 3, … 0, -1, -2, …) until the call stack overflows. Every recursive method needs a base case.
int power(int base, int exp) {
if (exp == 0) return 1;
return base * power(base, exp - 1);
}
Answer: C — 32
power(2,5) = 2 × power(2,4) = 2 × 2 × power(2,3) = … = 2⁵ = 32. Each recursive call multiplies base one more time, and the base case (exp == 0) returns 1.
int fib(int n) {
if (n <= 1) return n;
return fib(n-1) + fib(n-2);
}
Answer: C — 5 times
Drawing the recursion tree: fib(5) branches into fib(4)+fib(3), which further branches. The base cases (n=0 or n=1) are reached 5 times total: fib(1) is called 3 times, fib(0) is called 2 times.
Answer: C — O(2ⁿ)
Each call branches into two recursive calls, creating a binary tree of calls. The tree has roughly 2ⁿ nodes. This is why memoization or dynamic programming is essential for Fibonacci.
Answer: B — Memoization
Memoization stores the results of expensive function calls and returns the cached result when the same inputs occur again. It converts the exponential Fibonacci into O(n) by avoiding redundant computation.
Answer: B
Recursion and iteration are equally powerful — any recursive algorithm can be converted to an iterative one (often using an explicit stack) and vice versa. Recursion is often more elegant for problems with recursive structure (trees, divide-and-conquer), but iteration typically uses less memory since it avoids call stack overhead.
((a+b)*(c-d))Answer: B — Stack
Push each opening paren onto the stack. When you see a closing paren, pop and check for a match. If the stack is empty at the end with no mismatches, the expression is balanced. LIFO order naturally matches nested structures.
Answer: B
After push A,B,C,D: stack = [A,B,C,D] (D on top). Pop twice removes D, C: stack = [A,B]. Push E: stack = [A,B,E]. Pop once removes E: stack = [A,B]. Top = B.
Answer: C — Both O(1)
With a linked list, push adds a node at the head (O(1)) and pop removes the head node (O(1)). No shifting or resizing needed.
3 4 + 2 *Answer: C — 14
Push 3, push 4. See +: pop 4 and 3, compute 3+4=7, push 7. Push 2. See *: pop 2 and 7, compute 7*2=14, push 14. Result = 14.
Answer: B — FIFO
A queue processes elements in the order they arrive, like a line at a store. LIFO describes a stack. Highest priority first describes a priority queue.
Answer: C
FIFO: enqueue A,B,C,D (front=A, rear=D). Dequeue removes A, then B. Front is now C.
Answer: B — 4
Elements at indices 4, 5, 0, 1 (wrapping around). Count = (2 - 4 + 6) % 6 = 4. The formula (rear - front + capacity) % capacity handles the wrap-around.
Answer: B
Print jobs are processed in the order received (FIFO) — a perfect queue application. Undo/redo and browser history are stacks (LIFO). Expression evaluation uses a stack.
Answer: C — Leaf
A leaf node has no children (both left and right child are null). An internal node has at least one child. The root is the topmost node.
5
/ \
3 8
/ \
1 4
Answer: B — 5, 3, 1, 4, 8
Pre-order visits: root, left subtree, right subtree. So: 5 (root), then 3, 1, 4 (left subtree), then 8 (right subtree). Option A is in-order.
Answer: A — 2
A complete binary tree minimizes height. Height 2 gives 3 levels (0, 1, 2) with a maximum of 1 + 2 + 4 = 7 nodes — exactly 7. A perfectly complete binary tree of height 2 fits all 7 nodes. Height 1 can hold at most 3 nodes, so height 2 is the minimum.
Answer: B — In-order
In-order (left, root, right) visits BST nodes in ascending sorted order. This is a key property of BSTs and one of the most important things to know about tree traversals.
Answer: B — 1
A min-priority queue always removes the element with the smallest priority value, regardless of insertion order. Unlike a regular queue (FIFO), priority determines the exit order.
Answer: B — O(log n)
Insert adds the element at the bottom of the heap, then "bubbles up" to restore the heap property. The maximum number of swaps is the height of the tree = log n.
Answer: B
ER patients are seen based on severity (priority), not arrival order. A checkout line is a regular queue (FIFO). Undo history is a stack. Web browsing history is a stack.
Answer: A — O(1)
The minimum element is always at the root of a min-heap. You simply read the first element of the array. Removing it is O(log n), but just finding it is O(1).
Answer: A
In a min-heap, every parent must be ≤ its children. For index i: left child = 2i+1, right child = 2i+2. Option A: 1≤3, 1≤5, 3≤7, 3≤9, 5≤8, 5≤6 — all valid. Option C fails because 3 > 1 (root is not minimum).
Answer: B — Bubble down from the root
After removal, the last element is moved to the root, then "bubbled down" by swapping with its smaller child until the heap property is restored. This takes O(log n). Rebuilding from scratch would be O(n) — unnecessary.
Answer: C — O(n)
The bottom-up heapify approach starts from the last non-leaf and sifts down each node. Although it seems like it should be O(n log n), the mathematical analysis shows most nodes are near the bottom and require few swaps. The total work sums to O(n).
Answer: B — (i - 1) / 2
For 0-based indexing: parent = (i-1)/2 (integer division), left child = 2i+1, right child = 2i+2. For 1-based indexing, parent = i/2. This is a fundamental heap formula.
Answer: C — Slot 3
10 % 7 = 3, 17 % 7 = 3, 24 % 7 = 3. All three hash to slot 3. With chaining, they form a linked list at that slot.
Answer: B
Higher load factor = more elements per slot on average = more collisions = longer chains (or more probing). This is why hash tables resize when load factor exceeds a threshold (typically 0.75 in Java).
HashMap.get(key)?Answer: C — O(n)
In the worst case, all keys hash to the same bucket, creating one long chain of length n. Searching that chain is O(n). (Java 8+ converts long chains to balanced trees, making worst case O(log n), but the classic answer is O(n).)
Answer: C — HashMap
HashMap provides O(1) average-case lookup by key. An ArrayList or LinkedList would require O(n) linear search. A sorted array gives O(log n) with binary search but O(n) for insertions.
Answer: B — 7
5 becomes the root. 3 < 5, goes left. 7 > 5, goes right. So the right child of the root (5) is 7. Then 1 and 4 go into the left subtree under 3.
Answer: C — O(n)
If elements are inserted in sorted order (e.g., 1,2,3,4,5), the BST degenerates into a linked list (all right children). Search becomes O(n). Balanced BSTs (AVL, Red-Black) guarantee O(log n) worst case.
Answer: B — Keys are stored in sorted order
TreeMap is backed by a Red-Black tree, so keys are always sorted. This allows operations like finding the smallest key, range queries, and ordered iteration. HashMap is faster for lookup (O(1) vs O(log n)) but doesn't maintain order.
Answer: B
The in-order successor (smallest value in the right subtree) maintains the BST property because it's larger than everything in the left subtree and smaller than everything else in the right subtree. The in-order predecessor (largest in left subtree) also works.
Answer: B
Optimal substructure means the optimal solution contains optimal solutions to subproblems. Overlapping subproblems means the same subproblems are solved repeatedly. When both exist, DP avoids redundant computation by storing results.
Answer: B
Naive recursion recomputes fib(k) many times for each k. For example, fib(3) is computed multiple times when calculating fib(5). DP stores each result once, eliminating this redundancy.
Answer: B
Bottom-up DP starts from the smallest subproblems (base cases) and iteratively builds up to the desired answer. This contrasts with top-down (memoized recursion), which starts from the final problem and recurses down to base cases.
Answer: A — 2 coins (5 + 6)
A greedy approach (always pick the largest coin) would choose 6 + 5 = 11 in 2 coins, which happens to be optimal here. But greedy doesn't always work for coin change — DP systematically finds the true minimum by building up from smaller amounts.
CS 205 Shared Quiz Plan — Spring 2026
Generated for review by all collaborators. Last updated: February 2026.