A decision tree is a rooted tree that models a sequence of decisions, where:
- Each internal node represents a decision point (question/choice)
- Each edge represents a possible outcome/answer
- Each leaf node represents a final outcome or solution
[Start]
/ \
[Choice A] [Choice B]
/ \ \
[A1] [A2] [B1]
KEY TAKEAWAY: Decision trees make the search space of a problem explicit. The branching factor and depth determine the size of the search space — exponential growth is a key concern.
Find all routes from A to D in a graph. The decision tree represents choices at each step:
Root: at A
├── Go to B → at B
│ ├── Go to C → at C → Go to D [SOLUTION]
│ └── Go to D [SOLUTION]
└── Go to C → at C → Go to D [SOLUTION]
A state graph (state machine / state transition graph) is a directed graph where:
- Each node represents a state of a system
- Each directed edge represents a transition from one state to another
- Edges may be labelled with the condition or action that triggers the transition
Two jugs: 3L and 5L capacity. Goal: Measure exactly 4L.
- Each state: (amount in 3L jug, amount in 5L jug)
- Initial state: (0, 0)
- Goal state: (_, 4)
- Transitions: fill jug, empty jug, pour between jugs
(0,0) → fill 5L → (0,5) → pour to 3L → (3,2) → empty 3L → (0,2) → pour to 3L → (2,0) ... → (1,4) GOAL
EXAM TIP: For planning problems, distinguish whether to use a decision tree (enumerate all choices) or a state graph (model system states). State graphs allow cycles (revisiting states); decision trees typically do not re-visit states.
| Feature | Decision Tree | State Graph |
|---|---|---|
| Structure | Rooted tree (acyclic) | Directed graph (may have cycles) |
| Nodes represent | Decisions/choices | System states |
| Edges represent | Outcomes/choices | State transitions |
| Purpose | Enumerate solutions | Model system behaviour |
| Search | DFS (backtracking), BFS | BFS, DFS, Dijkstra’s |
| Typical use | Combinatorial search | Planning, AI search |