Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Additional Practice Roadmap

Follow this curated question flow to structure your DSA practice: https://neetcode.io/roadmap


Data Structures and Algorithms Review Checkpoint

Mixed Recall Before the Dedicated Tests and Optimization Topics

Pause, connect, and test the whole toolkit

You have met lists, stacks, trees, graphs, BFS, DFS, Dijkstra, cycle detection, and topological sort. This notebook turns that sequence into a compact review so you can decide which idea fits which problem before moving into deeper assessments and new algorithm families.

What to be able to do by the end

  • Match a business scenario to the right structure or traversal idea.

  • Explain how graph algorithms differ in purpose, not just in syntax.

  • Check your own understanding before opening the dedicated test notebook.

  • See how this chapter flows into greedy and dynamic-programming thinking.

review_cases = [
    {
        "scenario": "Store customer IDs without duplicates",
        "best_fit": "set",
        "reason": "Membership checks and uniqueness are the priority."
    },
    {
        "scenario": "Process support tickets in arrival order",
        "best_fit": "queue",
        "reason": "First-in, first-out keeps service fair."
    },
    {
        "scenario": "Find the fewest hops between unweighted pages",
        "best_fit": "bfs",
        "reason": "Breadth-first search reaches the closest layer first."
    },
    {
        "scenario": "Find the cheapest route across weighted roads",
        "best_fit": "dijkstra",
        "reason": "Weighted edges require cheapest-known distance updates."
    },
    {
        "scenario": "Check whether task dependencies contain a loop",
        "best_fit": "cycle detection",
        "reason": "A cycle means there is no valid dependency order."
    },
]

print("DSA review board")
print("=" * 32)

for index, case in enumerate(review_cases, start=1):
    print(f"{index}. {case['scenario']}")
    print(f"   Best fit : {case['best_fit']}")
    print(f"   Why      : {case['reason']}")
    print()

graph_tools = {
    "explore layers": "bfs",
    "explore one path deeply": "dfs",
    "cheapest weighted route": "dijkstra",
    "dependency order": "topological sort",
    "dependency loop check": "cycle detection",
}

print("Graph algorithm quick map")
for goal, method in graph_tools.items():
    print(f"- {goal:<27} -> {method}")
DSA review board
================================
1. Store customer IDs without duplicates
   Best fit : set
   Why      : Membership checks and uniqueness are the priority.

2. Process support tickets in arrival order
   Best fit : queue
   Why      : First-in, first-out keeps service fair.

3. Find the fewest hops between unweighted pages
   Best fit : bfs
   Why      : Breadth-first search reaches the closest layer first.

4. Find the cheapest route across weighted roads
   Best fit : dijkstra
   Why      : Weighted edges require cheapest-known distance updates.

5. Check whether task dependencies contain a loop
   Best fit : cycle detection
   Why      : A cycle means there is no valid dependency order.

Graph algorithm quick map
- explore layers              -> bfs
- explore one path deeply     -> dfs
- cheapest weighted route     -> dijkstra
- dependency order            -> topological sort
- dependency loop check       -> cycle detection

The Big Picture

The chapter has moved from how data is stored to how relationships are explored. That progression matters: once you can represent data clearly, you can start asking better questions about routes, order, reachability, and optimization.

If a topic still feels fuzzy, what should you revisit?
  • Revisit lists, dictionaries, and sets if your challenge is about choosing the right container.

  • Revisit stack_queue and linked-list notebooks if the order of processing or pointer-style navigation still feels abstract.

  • Revisit the graph sequence if you are unsure when to use BFS, DFS, Dijkstra, cycle detection, or topological sort.

Worked example: classify mixed business needs

A product team might ask all of these in the same week:

  1. Remove duplicate survey respondents.

  2. Process refund requests in the order they arrive.

  3. Find the fewest referral steps between two customers.

  4. Detect whether approval steps depend on each other in a loop.

Those are not four versions of the same problem. They point to four different tools: set, queue, bfs, and cycle detection. Strong DSA understanding is really the habit of spotting those differences early.

Runnable Review Check

Use this short diagnostic to connect question types to likely answers. Edit the learner choices if you want to simulate your own score.

Reflection prompt

When you miss a question, ask yourself whether the gap is about data representation, processing order, or graph reasoning. That tells you which earlier notebook to revisit.

questions = [
    ("Need unique values only", "set"),
    ("Need last-in, first-out undo behaviour", "stack"),
    ("Need the cheapest route on weighted edges", "dijkstra"),
    ("Need a valid dependency order in a DAG", "topological sort"),
]

learner_choices = {
    "Need unique values only": "set",
    "Need last-in, first-out undo behaviour": "stack",
    "Need the cheapest route on weighted edges": "dijkstra",
    "Need a valid dependency order in a DAG": "topological sort",
}

score = 0
print("Rapid recall")
print("-" * 32)

for prompt, answer in questions:
    learner_answer = learner_choices[prompt]
    is_correct = learner_answer == answer
    score += int(is_correct)
    print(prompt)
    print("  Your choice:", learner_answer)
    print("  Expected   :", answer)
    print("  Result     :", "Correct" if is_correct else "Review this topic")
    print()

print(f"Final score: {score}/{len(questions)}")
Rapid recall
--------------------------------
Need unique values only
  Your choice: set
  Expected   : set
  Result     : Correct

Need last-in, first-out undo behaviour
  Your choice: stack
  Expected   : stack
  Result     : Correct

Need the cheapest route on weighted edges
  Your choice: dijkstra
  Expected   : dijkstra
  Result     : Correct

Need a valid dependency order in a DAG
  Your choice: topological sort
  Expected   : topological sort
  Result     : Correct

Final score: 4/4

Interactive Code

Expected output
Topics reviewed: 4
Strongest area: graphs and graph algorithms
Expected output
deduplicate coupon codes -> set
serve customers in arrival order -> queue
find minimum-hop route -> bfs
schedule tasks with prerequisites -> topological sort

Guided Practice

Which structure is the best first choice for checking whether a username has already been seen?

listA list can work, but membership checks are not the main strength here.
setCorrect. A set is built for uniqueness and fast membership testing.
queueA queue models service order, not uniqueness.
tupleA tuple stores fixed ordered values, not uniqueness logic.

If all graph edges have equal cost and you want the fewest hops, which algorithm fits best?

BFSCorrect. BFS explores layer by layer, so it finds minimum-hop paths first.
DFSDFS can reach the target, but it does not guarantee the fewest hops first.
Cycle detectionCycle detection answers a different question: whether a loop exists.
Stack push/popThat is a data-structure operation, not a path-finding algorithm.

Why does Dijkstra’s algorithm matter when BFS is not enough?

Because BFS cannot use a queueBFS absolutely uses a queue.
Because weighted edges require cheapest-known distance updatesCorrect. Dijkstra chooses the lowest tentative total cost, not just the next layer.
Because Dijkstra only works on treesIt works on weighted graphs with non-negative weights, not only trees.
Because Dijkstra avoids visiting neighborsIt still evaluates neighbors while relaxing distances.

What does a cycle in task prerequisites tell you?

The graph is guaranteed to be weightedCycles say nothing about edge weights.
BFS will always failTraversal may still run; the issue is valid dependency order.
No valid topological ordering exists until the loop is brokenCorrect. A cycle means some task depends on itself indirectly.
A dictionary should replace the graphChanging containers does not remove the logical dependency loop.

Exercises

  1. Build a dictionary that maps each business need below to its best-fit structure or algorithm: undo history, unique visitors, shortest weighted route, task order with prerequisites.

  2. Create a small graph and decide whether BFS or Dijkstra is more appropriate. Explain your choice in one sentence.

  3. Write a two-column comparison of DFS and topological sort. Focus on goal rather than implementation details.

Starter code
business_tools = {
    "undo history": "",
    "unique visitors": "",
    "shortest weighted route": "",
    "task order with prerequisites": "",
}

for need, tool in business_tools.items():
    print(need, "->", tool)
Hint / solution direction
  • undo history usually suggests a stack.

  • unique visitors usually suggests a set.

  • shortest weighted route suggests dijkstra.

  • task order with prerequisites suggests topological sort, but only after checking for cycles if the data may be messy.

Key Takeaway

The chapter is no longer about isolated definitions. It is about choosing the right mental tool for the problem in front of you: a container for storage, a process structure for order, or a graph algorithm for relationships and routes.

The next notebook, DSA_test_1, gives you a more direct self-check. After that, greedy_algorithms and dynamic_programming will show what happens when the problem is not only about representing data well, but also about making increasingly smart optimization decisions.