Practice Discrete Math

Algorithms / Graph Modeling State Space

Least You Need to Know: Modeling Interview Problems as Graph Search

Many interview problems become easier once you name the **state** and the **moves**. When states become vertices and legal moves become edges, familiar tools like BFS and DFS suddenly apply.

The least you need to know

Key notation

state a complete description of one intermediate situation
neighbor a state reachable in one legal move
implicit graph a graph whose neighbors are generated when needed rather than listed in advance

Tiny worked example

  • In a word-ladder problem, each valid word can be treated as a node.
  • Two words share an edge when one allowed transformation changes one into the other.
  • Then the fewest transformations question becomes a shortest-path-by-edge-count question.
  • That is why BFS is the natural default when each move costs one step.

Common mistakes

How to recognize this kind of problem

Next recommended lesson

Continue through this topic with Least You Need to Know: BFS, DFS, and Connected Components.

Least You Need to Know: BFS, DFS, and Connected Components

Related lessons

Keep going with nearby lessons in the same topic.

More ways to explore

Start practice