College prep
Prepare for a practical or viva with worked examples and dry runs.
Array and linked-list practicals
Draw storage locations and logical sequence separately.
Insert 6 at index 1 of [2, 5, 9]. Which writes happen first?
With spare capacity, shift 9 to index 3 and 5 to index 2, then store 6 at index 1. Shifting from the right preserves unread items.Delete B from A → B → C using a reference to A.
Set A.next to B.next. In a manually managed language release B when no live owner still needs it. The logical chain is A → C.Stacks, queues and expressions
Record the contents of each active end after consuming one token.
Why does a circular queue need a size or spare slot?
With only head and tail modulo capacity, equal indices can represent either full or empty. A size field or a reserved empty position distinguishes those states.Convert A+B*C to postfix.
Emit A and B, keep + and * pending, then emit C. Pop * before + due to precedence. The result is A B C * +.Evaluate 8 3 − 2 ×.
Push 8 then 3. Pop the right operand 3 before the left operand 8, push 5, then multiply by 2 to obtain 10.Recursion and sorting passes
Show one complete return or pass before giving the final output.
How many moves does Hanoi use for three disks?
Move two disks aside in 3 moves, move the largest once and restore the two in 3 moves. The total is 7, following T(n) = 2T(n−1)+1.What does one bubble pass guarantee?
In a left-to-right increasing sort, the largest active value reaches the rightmost active position. For [3, 2, 1], the pass ends at [2, 1, 3].What is live on the factorial(3) stack?
With base case 0, the deepest point has frames for 3, 2, 1 and 0. Returning 1 from zero allows multiplication by 1, then 2, then 3.BSTs and AVL repairs
Maintain both search order and the extra balance condition when rotating.
Insert 30, 20, 10 into an AVL tree.
30 becomes heavy on the left-left path. A right rotation at 30 makes 20 the root, with 10 and 30 as children. Inorder still gives 10, 20, 30.When is a double rotation needed?
A left-heavy node with a right-heavy left child needs a left rotation on the child and then a right rotation on the node. The symmetric case uses right then left.Why use bounds to validate a BST?
Every node in the left subtree must remain below its ancestor’s upper bound. Checking only a node and its direct parent does not verify this transitive restriction.Graph laboratory
State graph direction, edge costs and the objective before choosing an algorithm.
Trace Dijkstra from A with A→B=4, A→C=1, C→B=2.
Start with A=0, B=∞, C=∞. After A, distances are B=4, C=1. Settle C and relax B to 3. Settle B to finish.How does a minimum spanning tree differ from a shortest-path tree?
A minimum spanning tree minimizes the sum of selected edges connecting all vertices in an undirected graph. A shortest-path tree preserves distances from a particular source.Which edge does Kruskal reject in a triangle of costs 1, 2, 4?
The edges of costs 1 and 2 connect all three vertices. Adding cost 4 would make a cycle in the selected forest, so reject it.Why does BFS mark at enqueue time?
Two parents might discover the same neighbor before it is processed. Marking when enqueuing gives that vertex a single queue entry and records its first-layer distance.Pause and Predict
Pause a binary search before the boundary update and predict its next interval.
Find 19 in the sorted array. The current midpoint is index 3.
- 20
- 51
- 72
- 11probe 3
- 144
- 195
- 236
Which action should the search take now?