Use Chain of Thought, zero-shot CoT, and tree of thought prompting to improve LLM reasoning accuracy.
Published May 11, 2025
Chain of Thought prompting guides LLMs to think step by step before reaching a conclusion. It dramatically improves performance on math, logic, and multi-step reasoning tasks.
❌ Standard (often wrong on complex problems):
Q: If there are 3 cars, each with 4 wheels, and 2 motorcycles each with 2 wheels, how many wheels total?
A: 16
✅ Chain of Thought:
Q: [same question] Let's think step by step.
A: Cars: 3 × 4 = 12 wheels
Motorcycles: 2 × 2 = 4 wheels
Total: 12 + 4 = 16 wheels
Simply appending this phrase triggers reasoning in GPT-4-class models:
"What is the time complexity of merging two sorted arrays of size n and m?
Let's think step by step."
Response:
Step 1: We need to compare elements from both arrays
Step 2: Each comparison advances one pointer by 1
Step 3: Total comparisons ≤ n + m (each element processed once)
Step 4: Therefore time complexity is O(n + m)
Provide examples showing the reasoning chain:
Q: I have 5 apples. I give 2 to Alice and 1 to Bob. How many do I have?
A: Start with 5 apples. Give 2 to Alice: 5-2=3. Give 1 to Bob: 3-1=2. Answer: 2.
Q: A train leaves at 9am traveling 60mph. Another leaves at 10am going 80mph.
When does the second catch the first?
A: [let the model continue the pattern]
"Analyze this algorithm:
[code]
Reason through:
1. What does each section do?
2. What data structures are used and why?
3. What is the time complexity? (show derivation)
4. What is the space complexity?
5. Can it be optimized? If so, how?"
Explore multiple reasoning paths and evaluate which is best:
"I need to design a caching system for 10M users.
Explore three different architectures:
Option A: Redis cluster with consistent hashing
- Design: ...
- Pros: ...
- Cons: ...
Option B: Memcached with client-side sharding
...
Option C: Application-level caching with Caffeine
...
Given our constraints (high availability, < 5ms latency), recommend the best option and justify."
Generate multiple reasoning chains and take the majority answer:
import openai
from collections import Counter
def self_consistent_answer(question, n=5):
answers = []
for _ in range(n):
response = openai.chat.completions.create(
model="gpt-4",
messages=[{"role": "user",
"content": question + "\nLet's think step by step."}],
temperature=0.7 # diversity in reasoning paths
)
# Extract final answer from response
answers.append(extract_answer(response))
return Counter(answers).most_common(1)[0][0] # majority vote
"Review this Java method for bugs:
[code]
Reason through:
1. What is the function supposed to do?
2. Trace through the logic with input [example]
3. Are there edge cases not handled?
4. Are there concurrency issues?
5. State any bugs found and fixes."
✅ Multi-step math and logic ✅ Algorithm analysis ✅ Debugging (trace through code) ✅ System design trade-off analysis
❌ Simple factual lookups ("What is the capital of France?") ❌ Creative tasks (CoT adds verbosity without benefit)