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

DS

Breadth-first search

Starting at A, list visited vertices. Process each vertex’s neighbors alphabetically and treat the edges as undirected.

Intermediate
DS

Depth-first search

List the DFS visit order starting from A. Visit available neighbors in alphabetical order and use undirected edges.

Intermediate
DS

Backtracking with choices

List every two-letter string with no duplicates, exploring letters in the order given.

Intermediate
DS

Merge sort

What two sorted halves are merged in the final step?

Intermediate
DS

Quicksort and partitioning

Which three groups does a three-way partition produce?

Intermediate
DS

Heaps and priority queues

Which priority is exposed at the top next?

Intermediate
DS

Binary search trees

Which keys are visited when searching for 5?

Intermediate
DS

Algorithm invariants

What should total be before processing the third item?

Intermediate
DS

Adjacency lists and matrices

Which neighbor lists change?

Intermediate
DS

Counting sort

What are the counts for 0, 1, 2, and 3?

Intermediate
DS

Dijkstra’s shortest paths

Find the cost of the cheapest route from A to B along the listed directed edges.

Advanced
DS

Dynamic programming

Count ordered ways to climb exactly n stairs, using one- or two-stair moves.

Advanced
DS

Tries and prefix search

Is ca a stored word, a prefix, or both?

Advanced
DS

Union-find and connected groups

Which items share a group with A?

Advanced
DS

Topological sorting

Give one valid order.

Advanced
DS

Greedy interval scheduling

Which intervals does earliest finish select?

Advanced
DS

Minimum spanning trees

What is the cost of the minimum spanning tree?

Advanced
DS

Bellman–Ford and negative edges

What distance should replace 8?

Advanced
DS

0/1 knapsack

What is the highest value?

Advanced
DS

Longest common subsequence

Give a longest common subsequence.

Advanced