Practice problems
Choose a topic, work through an example, and reveal a hint or worked answer when you’re ready.
Showing 81–100 of 145 problems
Breadth-first search
Starting at A, list visited vertices. Process each vertex’s neighbors alphabetically and treat the edges as undirected.
Depth-first search
List the DFS visit order starting from A. Visit available neighbors in alphabetical order and use undirected edges.
Backtracking with choices
List every two-letter string with no duplicates, exploring letters in the order given.
Merge sort
What two sorted halves are merged in the final step?
Quicksort and partitioning
Which three groups does a three-way partition produce?
Heaps and priority queues
Which priority is exposed at the top next?
Binary search trees
Which keys are visited when searching for 5?
Algorithm invariants
What should total be before processing the third item?
Adjacency lists and matrices
Which neighbor lists change?
Counting sort
What are the counts for 0, 1, 2, and 3?
Dijkstra’s shortest paths
Find the cost of the cheapest route from A to B along the listed directed edges.
Dynamic programming
Count ordered ways to climb exactly n stairs, using one- or two-stair moves.
Tries and prefix search
Is ca a stored word, a prefix, or both?
Union-find and connected groups
Which items share a group with A?
Topological sorting
Give one valid order.
Greedy interval scheduling
Which intervals does earliest finish select?
Minimum spanning trees
What is the cost of the minimum spanning tree?
Bellman–Ford and negative edges
What distance should replace 8?
0/1 knapsack
What is the highest value?
Longest common subsequence
Give a longest common subsequence.