LeetCodechevron_rightSolve patternschevron_rightgraph dfs traversal
schemaReusable solving pattern

graph dfs traversal Pattern

Pattern hubs are for building transferable solving frames. Learn the recognition signals first, then drill state definition, update rules, and edge explanation until the pattern feels stable.

database43 problemstune1/26/16 difficulty mixcategory6 linked topics

Pattern brief

Recognize first

Do you understand the importance of using a hash table to store visited nodes during graph traversal?

Solve rhythm

State the active state and invariant first, explain how each update preserves them, then pressure-test with counterexamples.

Most common miss

Not using a hash table to track cloned nodes, leading to cycles and duplicate clones.

Recognition signals

  • Do you understand the importance of using a hash table to store visited nodes during graph traversal?
  • Can you describe how to handle cycles when cloning a graph using DFS?
  • Candidate identifies graph representation with adjacency lists.

Solve flow

  1. 1. Define the active state/window.
  2. 2. Update state while preserving invariants.
  3. 3. Validate with edge-heavy examples.

Common misses

  • Not using a hash table to track cloned nodes, leading to cycles and duplicate clones.
  • Failing to sort adjacency lists leading to incorrect lexical order.
  • Forgetting to add the inverse edge 1/value, which breaks paths in DFS.

Recommended Ladder

Problem bank

graph dfs traversal pattern bank

Start by scanning with search or difficulty filters, then narrow by linked topics. The bank continues loading inside its own container so the page stays readable.

Progressive pattern bank

Use it to build pattern understanding first, then expand into the full corpus.

hourglass_bottomScroll inside to continue
search
tuneDifficulty
categoryTopic focus

Showing 24 / 43 problems

+24 per load
#TitleDifficulty
133

Clone Graph

Clone Graph involves cloning a graph using DFS, focusing on graph traversal and neighbor management using hash tables.

Medium
332

Reconstruct Itinerary

Reconstruct Itinerary requires building a valid travel route using all tickets once, starting from JFK with lexical orde…

Hard
399

Evaluate Division

Compute the results of division queries from given equations using graph traversal and depth-first search efficiently.

Medium
547

Number of Provinces

Solve Number of Provinces by scanning the adjacency matrix and launching DFS once per unvisited city component.

Medium
684

Redundant Connection

Identify and remove the redundant edge that causes a cycle in a graph starting as a tree.

Medium
685

Redundant Connection II

Find and remove the redundant connection in a directed graph that was originally a rooted tree.

Hard
743

Network Delay Time

Find the minimum time for a signal to travel to all nodes in a directed graph or determine if it's impossible.

Medium
753

Cracking the Safe

The Cracking the Safe problem involves finding the shortest password sequence to unlock a safe using graph traversal and…

Hard
765

Couples Holding Hands

This problem requires arranging couples sitting apart in a row with the minimum number of swaps using graph traversal an…

Hard
785

Is Graph Bipartite?

Determine whether an undirected graph can be split into two independent sets using DFS, BFS, or Union Find patterns.

Medium
787

Cheapest Flights Within K Stops

Find the cheapest flight from a source to a destination with at most K stops using graph traversal techniques efficientl…

Medium
797

All Paths From Source to Target

Find all paths in a directed acyclic graph (DAG) from source to target using depth-first search and backtracking.

Medium
834

Sum of Distances in Tree

The problem asks to compute the sum of distances between each node and all others in a tree structure using depth-first …

Hard
841

Keys and Rooms

Determine if all rooms can be visited given keys distributed across a set of interconnected locked rooms using graph tra…

Medium
886

Possible Bipartition

Determine if a group of n people with mutual dislikes can be split into two non-conflicting groups using graph traversal…

Medium
947

Most Stones Removed with Same Row or Column

Maximize the number of stones removed from a 2D plane using graph traversal and DFS.

Medium
1042

Flower Planting With No Adjacent

In this problem, you are tasked with planting flowers in gardens with specific constraints based on graph traversal prin…

Medium
1192

Critical Connections in a Network

Find critical connections in a network of servers, ensuring efficient traversal using depth-first search and Tarjan's al…

Hard
1319

Number of Operations to Make Network Connected

Determine the minimum number of operations required to connect all computers in a network with a limited number of cable…

Medium
1361

Validate Binary Tree Nodes

Validate Binary Tree Nodes problem requires checking if a set of nodes forms a valid binary tree using graph traversal.

Medium
1377

Frog Position After T Seconds

The problem asks for the probability that a frog reaches a target vertex after t seconds in a tree graph.

Hard
1466

Reorder Routes to Make All Paths Lead to the City Zero

Reorder Routes to Make All Paths Lead to the City Zero involves reversing the direction of roads in a tree to ensure all…

Medium
1971

Find if Path Exists in Graph

Determine if a valid path exists between two vertices in a bi-directional graph using traversal techniques.

Easy
2092

Find All People With Secret

Find all people who receive a secret through meetings using graph traversal with depth-first search efficiently and corr…

Hard

swap_vertScroll inside the bank to auto-load more

Continue by topic

Once the pattern itself feels familiar, move back into concrete topic hubs so you can separate the pattern from the changing problem context.

route

Guided Practice Path

AI recommends problems by your level and tracks your progress.

Start Guided Patharrow_forward
Graph traversal with depth-first search LeetCode Pattern: 43 Solutions