Count the real cost
Derive the exact comparison count and Θ bound for two consecutive loops of sizes n and n/2.
From recognition to implementation
34 focused exercises covering traces, coding patterns, complexity arguments, and design choices. Each card tells you the intended technique and links back to the relevant lesson.
Showing 34 of 34 exercises
Derive the exact comparison count and Θ bound for two consecutive loops of sizes n and n/2.
Order log n, n log n, n², 2ⁿ, and n! and estimate which remain usable at n=50.
Compare repeated Fibonacci recursion, memoisation, and an iterative two-variable solution for n=45.
Rotate a vector right by k positions without allocating another vector.
Find the length of the longest substring with no repeated character.
Reverse a singly linked list iteratively and state the loop invariant.
Detect whether a linked list contains a cycle without modifying nodes.
Design get and put for a fixed-capacity least-recently-used cache.
Validate (), [], and {} while reporting the first bad index.
For every array element, find the first greater element to its right.
Implement FIFO enqueue and dequeue using only two stacks.
Return the first array value whose frequency reaches two.
Explain how poor hashing turns expected O(1) lookup into O(n), then propose two mitigations.
Return the first index of target in a sorted array containing duplicates.
Given workloads and h hours, find the smallest integer speed that finishes all work.
Locate a key in a strictly increasing array rotated at an unknown pivot.
Sort pairs by key and identify which syllabus algorithms preserve equal-key order.
Show why insertion sort is efficient when each item is at most k positions away.
Count pairs i<j with a[i]>a[j] without checking all pairs.
Find the kth smallest element without fully sorting the input.
Reconstruct a binary tree from preorder and inorder sequences with distinct keys.
Determine whether every node satisfies global BST bounds, not just its parent relation.
Find the lowest shared ancestor of two keys in a BST.
Insert 50,30,70,20,40,35 and record balance factors and rotations after each step.
Report the kth largest value after every item in a stream.
Merge k sorted arrays while keeping only one candidate from each array.
Count connected components in an undirected graph and label every vertex.
Return the actual shortest path between two vertices in an unweighted graph.
Detect a cycle in a directed dependency graph.
Implement Dijkstra with stale-entry rejection and reconstruct the selected route.
Process union and connected queries using path compression and union by size.
Run Prim and Kruskal on the same weighted graph and explain why their edge order differs but total weight agrees.
Design a quadtree range query that skips quadrants not intersecting a rectangle.
Choose graph and spatial structures for bin locations, road travel, updates, and daily route queries.