Course contentsShow
← AI Engineering
Lesson 192 of 1,8865. Advanced Prompting TechniquesFree lesson

Implementing ToT with Breadth-First and Depth-First Search

Structure prompt sequences to explore thought branches systematically using search strategies.

Implementing ToT with Breadth-First and Depth-First Search

What you'll learn: How to structure prompt sequences that systematically explore Tree-of-Thought branches using BFS and DFS strategies.

The Core Idea

You've learned that Tree-of-Thought (ToT) explores multiple solution paths. But how do you decide which paths to explore first? That's where search strategies come in.

Breadth-First Search (BFS) explores all branches at the current level before going deeper. Think of it like checking every door on one floor of a building before taking the stairs.

Depth-First Search (DFS) follows one path all the way to the end before backtracking. It's like walking down one hallway to its conclusion, then returning to try the next.

Structuring Prompts for Search Strategies

BFS Approach

Generate all possible "next thoughts" at once, evaluate them, then expand the best ones:

Round 1: Generate 3 initial approaches to the problem
Round 2: For each promising approach, generate next steps
Round 3: Evaluate all second-level thoughts before proceeding

This creates wider, shallower exploration—good when you need to compare many alternatives early.

DFS Approach

Follow one reasoning chain completely before trying another:

Path 1: Initial thought → refinement → sub-refinement → conclusion
Path 2: Different initial thought → its refinements → conclusion

This creates deeper exploration of fewer paths—efficient when early thoughts are likely correct.

When to Use Each

Use BFS when solution quality matters more than speed, and you want comprehensive coverage. Use DFS when you have good intuition about promising paths and want faster results.

You implement these by structuring your prompt sequences: either generating multiple options simultaneously (BFS) or chaining prompts sequentially down one path before backtracking (DFS).

Key Takeaway: BFS and DFS in ToT are implemented through different prompt sequencing patterns—parallel expansion for breadth-first, sequential chaining for depth-first.