From Linear Thinking to Branching Ideas: Exploring Tree of Thoughts in Prompt Engineering 🧑‍💻️🔗🌲

Digvijay Bhakuni
4 min readDec 7, 2024

--

Prompt engineering is the art of crafting instructions or prompts to guide AI models like ChatGPT or GPT-4 toward solving problems effectively. Two powerful techniques in prompt engineering are Chain of Thoughts (CoT) and Tree of Thoughts (ToT). While both methods focus on helping the model reason through a problem, Tree of Thoughts introduces better flexibility and adaptability, making it a game-changer in solving complex tasks.

Let’s break these concepts down for someone just starting with prompt engineering.

Photo by Brandon Green on Unsplash

⛓️What is Chain of Thoughts (CoT)?

Chain of Thoughts (CoT) is a linear reasoning process. It asks the model to break down a problem into a series of logical, step-by-step instructions. Each step builds on the previous one, just like following a recipe or solving a math problem.

CoT works great for tasks where each step of the reasoning depends on the previous one, such as solving arithmetic problems, logical puzzles, or answering factual questions.

🍎 Example of Chain of Thoughts

Let’s consider the problem:
“If Sam has 3 apples and buys 2 more, how many apples does Sam have now?”

Here’s how CoT might tackle this:

Step 1: Sam has 3 apples initially.
Step 2: Sam buys 2 more apples.
Step 3: Total apples Sam has = 3 + 2.
Step 4: The answer is 5.

In this approach, the reasoning is linear and straightforward, making it perfect for problems that don’t require considering multiple possibilities.

🌲What is Tree of Thoughts (ToT)?

Tree of Thoughts (ToT) takes reasoning a step further by introducing a branching structure of ideas. Instead of following a single linear path, the model explores multiple possible solutions or reasoning paths at the same time, evaluates them, and selects the best one.

This approach is inspired by decision trees in problem-solving, where the “tree” branches into different possibilities, and you can prune (eliminate) unhelpful branches to focus on the most promising solutions.

ToT is ideal for complex tasks that require exploration, self-reflection, and evaluation. It works well for creative tasks, planning, or situations where there isn’t a single clear solution from the outset.

🍏 Example of Tree of Thoughts

Let’s consider the same question:
“If Sam has 3 apples and buys 2 more, how many apples does Sam have now?”

Instead of working linearly, ToT might generate multiple reasoning paths like this:

Branch 1:
- Thought 1: Sam has 3 apples initially.
- Thought 2: Sam buys 2 more apples.
- Conclusion: Total apples = 3 + 2 = 5.

Branch 2 (Exploring a mistake):
- Thought 1: Maybe Sam starts with 5 apples.
- Thought 2: He buys 2 more apples.
- Conclusion: Total apples = 5 + 2 = 7. (This branch is incorrect.)

Branch 3 (Alternative reasoning):
- Thought 1: Sam has 3 apples.
- Thought 2: Adding 2 apples means counting two more: 4, 5.
- Conclusion: Total apples = 5.

Here, the model evaluates all branches, identifies that Branch 1 gives the correct reasoning, and prunes the incorrect paths (e.g., Branch 2). This ability to explore multiple options and self-correct makes ToT more powerful for complex or ambiguous tasks.

🆚 How ToT is Different and Better Than CoT

Here’s a side-by-side comparison to help you understand the differences:

| Feature             | Chain of Thoughts (CoT)               | Tree of Thoughts (ToT)                             |
|---------------------|---------------------------------------|----------------------------------------------------|
| Reasoning Structure | Linear (one step after another) | Branching (multiple paths explored) |
| Flexibility | Limited to a single reasoning path | Explores multiple possibilities simultaneously |
| Use Cases | Works well for simple, linear problems| Ideal for complex, creative, or ambiguous problems |
| Self-Correction | Limited (follows a fixed path) | Can evaluate and prune incorrect branches |
| Efficiency | Faster for straightforward tasks | More robust for complex tasks |

🔜 When to Use Each Approach

Use CoT when:

  • The problem is straightforward and has a clear logical progression.
  • You’re solving math problems, logical puzzles, or tasks requiring step-by-step reasoning.

Use ToT when:

  • The problem is complex, ambiguous, or requires exploring multiple solutions.
  • Tasks involve planning, decision-making, or creative problem-solving.
  • You want the model to self-reflect and evaluate its reasoning paths.

Why Tree of Thoughts is Revolutionary 🎄💭

Tree of Thoughts is better suited for real-world applications because it mimics how humans think when solving complex problems. We rarely stick to a single path; instead, we brainstorm multiple ideas, evaluate them, and choose the best one. ToT gives AI models this kind of flexibility, making them smarter and more adaptable.

For example:

  • In creative writing, ToT can explore multiple plot ideas before settling on the best one.
  • In planning, it can evaluate different strategies and choose the most efficient one.
  • In decision-making, it can simulate various scenarios and pick the optimal solution.

Conclusion 🔚

While Chain of Thoughts is a great starting point for reasoning-based tasks, Tree of Thoughts takes it a step further by enabling multi-path exploration and self-evaluation. For someone starting with prompt engineering, understanding when and how to use these techniques can significantly improve how you guide AI models to solve problems.

Both approaches are essential tools in your prompt engineering toolbox. Start with CoT for simple problems, and graduate to ToT when tackling complex, creative, or ambiguous tasks.

Citations and Further Reading

  1. Wei, J., et al. (2022). “Chain of Thought Prompting Elicits Reasoning in Large Language Models.” arXiv
  2. Yao, S., et al. (2023). “Tree of Thoughts: Deliberate Problem Solving with Large Language Models.” arXiv
  3. OpenAI Documentation: Prompt Engineering Techniques
  4. Google AI Blog: “Chain of Thought Prompting in AI”

By understanding these techniques and practicing with them, you’ll unlock the full potential of AI models in solving diverse challenges. Happy prompting! 🚀

--

--

No responses yet