Bird
Raised Fist0
Agentic AIml~20 mins

Tree-of-thought for complex decisions in Agentic AI - Practice Problems & Coding Challenges

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Challenge - 5 Problems
🎖️
Tree-of-thought Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
What is the main advantage of using a tree-of-thought approach in AI decision-making?
Consider an AI agent facing a complex problem with many possible steps. What is the main advantage of using a tree-of-thought approach compared to a simple linear reasoning process?
AIt allows the AI to explore multiple possible reasoning paths before choosing the best one.
BIt guarantees the AI will find the perfect solution every time without any errors.
CIt reduces the number of possible decisions by ignoring less important options.
DIt forces the AI to follow a fixed sequence of steps without deviation.
Attempts:
2 left
💡 Hint
Think about how exploring different paths helps in complex problems.
Predict Output
intermediate
2:00remaining
What is the output of this tree-of-thought simulation code?
Given the following Python code simulating a simple tree-of-thought search, what will be printed?
Agentic AI
def tree_search(node, depth):
    if depth == 0 or not node['children']:
        return node['value']
    results = []
    for child in node['children']:
        results.append(tree_search(child, depth - 1))
    return max(results)

root = {
    'value': 0,
    'children': [
        {'value': 3, 'children': []},
        {'value': 5, 'children': [
            {'value': 2, 'children': []},
            {'value': 7, 'children': []}
        ]},
        {'value': 1, 'children': []}
    ]
}

print(tree_search(root, 2))
A0
B7
C3
D5
Attempts:
2 left
💡 Hint
The function returns the maximum value found up to the given depth.
Hyperparameter
advanced
2:00remaining
Which hyperparameter most directly controls the breadth of exploration in a tree-of-thought search?
In a tree-of-thought AI system, which hyperparameter controls how many different reasoning paths the system explores at each step?
ADepth limit
BBatch size
CLearning rate
DBranching factor
Attempts:
2 left
💡 Hint
Think about how many child nodes are considered at each decision point.
Metrics
advanced
2:00remaining
Which metric best evaluates the quality of decisions made by a tree-of-thought AI agent?
When assessing a tree-of-thought AI agent solving complex problems, which metric best measures how good the final decisions are?
ATime taken to run the search
BNumber of nodes expanded during search
CAccuracy of final solution compared to ground truth
DMemory usage during computation
Attempts:
2 left
💡 Hint
Focus on the quality of the solution, not the resource usage.
🔧 Debug
expert
3:00remaining
Why does this tree-of-thought search code get stuck in an infinite loop?
Examine the code below. Why does the tree-of-thought search get stuck and never finish?
Agentic AI
def search(node, visited=None):
    if visited is None:
        visited = set()
    if node['id'] in visited:
        return None
    visited.add(node['id'])
    if not node['children']:
        return node['value']
    results = []
    for child in node['children']:
        results.append(search(child, visited))
    return max(filter(None, results))

node_a = {'id': 'A', 'value': 1, 'children': []}
node_b = {'id': 'B', 'value': 2, 'children': [node_a]}
node_a['children'] = [node_b]

print(search(node_a))
AThe code does not handle cycles properly because the visited set is shared and nodes are revisited.
BThe visited set is shared across recursive calls, causing incorrect skipping of nodes.
CThe max function fails because results list is empty due to filtering None values.
DThe recursion depth is too shallow, so the search stops prematurely.
Attempts:
2 left
💡 Hint
Consider how cycles in the graph affect recursion and visited nodes.

Practice

(1/5)
1.

What is the main purpose of using a tree-of-thought approach in complex decisions?

easy
A. To avoid making any decision
B. To randomly select an action without analysis
C. To break down decisions into smaller, manageable steps
D. To speed up decisions by ignoring options

Solution

  1. Step 1: Understand the concept of tree-of-thought

    Tree-of-thought breaks complex decisions into smaller steps to simplify the process.
  2. Step 2: Identify the purpose of breaking down decisions

    This helps explore options carefully and find better solutions.
  3. Final Answer:

    To break down decisions into smaller, manageable steps -> Option C
  4. Quick Check:

    Tree-of-thought = smaller steps [OK]
Hint: Think of breaking big problems into small parts [OK]
Common Mistakes:
  • Confusing tree-of-thought with random choice
  • Thinking it avoids decisions
  • Assuming it speeds up by ignoring options
2.

Which of the following correctly represents a step in building a tree-of-thought?

1. Start with initial state
2. Generate possible actions
3. Evaluate outcomes
4. Choose best path
easy
A. Choose best path, generate actions, start with initial state, evaluate outcomes
B. Start with initial state, generate actions, evaluate outcomes, choose best path
C. Evaluate outcomes, choose best path, start with initial state, generate actions
D. Generate actions, start with initial state, choose best path, evaluate outcomes

Solution

  1. Step 1: Identify the logical order of steps

    We start from the initial state, then generate possible actions.
  2. Step 2: Follow with evaluation and choice

    After generating actions, we evaluate outcomes and choose the best path.
  3. Final Answer:

    Start with initial state, generate actions, evaluate outcomes, choose best path -> Option B
  4. Quick Check:

    Logical step order = B [OK]
Hint: Follow the natural decision flow order [OK]
Common Mistakes:
  • Mixing up the order of steps
  • Starting with choice before generating actions
  • Evaluating before generating actions
3.

Given the following simplified tree-of-thought code snippet, what is the printed output?

def tree_of_thought(state, depth):
    if depth == 0:
        return [state]
    results = []
    for action in ['A', 'B']:
        next_state = state + action
        results.extend(tree_of_thought(next_state, depth - 1))
    return results

print(tree_of_thought('', 2))
medium
A. ['AA', 'AB', 'BA', 'BB']
B. ['A', 'B']
C. ['', 'A', 'B']
D. ['AA', 'AB', 'BA']

Solution

  1. Step 1: Understand recursion and depth

    At depth 2, the function appends two actions at each step, building strings of length 2.
  2. Step 2: Trace the recursive calls

    Starting with '', actions 'A' and 'B' add to form 'A' and 'B', then again add 'A' or 'B' to form 'AA', 'AB', 'BA', 'BB'.
  3. Final Answer:

    ['AA', 'AB', 'BA', 'BB'] -> Option A
  4. Quick Check:

    All 2-length action combos = C [OK]
Hint: Count depth levels and action combinations [OK]
Common Mistakes:
  • Confusing depth with number of actions
  • Returning partial strings
  • Missing recursive expansion
4.

Identify the error in this tree-of-thought function that prevents it from exploring all branches:

def tree_of_thought(state, depth):
    if depth == 0:
        return [state]
    results = []
    for action in ['A', 'B']:
        next_state = state + action
        results.append(tree_of_thought(next_state, depth - 1))
    return results

print(tree_of_thought('', 2))
medium
A. Using append instead of extend causes nested lists
B. Missing base case for depth == 0
C. Looping over wrong actions
D. Returning results before recursion

Solution

  1. Step 1: Analyze list operations in recursion

    Using append adds the entire recursive list as a single element, creating nested lists.
  2. Step 2: Correct method to flatten results

    Using extend adds elements individually, flattening the list as intended.
  3. Final Answer:

    Using append instead of extend causes nested lists -> Option A
  4. Quick Check:

    append vs extend affects list shape [OK]
Hint: Use extend to flatten recursive results [OK]
Common Mistakes:
  • Confusing append and extend
  • Ignoring base case presence
  • Misunderstanding recursion flow
5.

You want to use tree-of-thought to decide the best sequence of moves in a game where each move has a score. Which approach best fits this goal?

def tree_of_thought(state, depth):
    if depth == 0:
        return [(state, score(state))]
    results = []
    for action in possible_actions(state):
        next_state = apply_action(state, action)
        results.extend(tree_of_thought(next_state, depth - 1))
    return results

# How to choose best sequence?
hard
A. Stop recursion early without exploring all sequences
B. Pick the first sequence returned without comparing scores
C. Ignore scores and choose randomly
D. After collecting all sequences and scores, select the sequence with the highest score

Solution

  1. Step 1: Understand the goal of maximizing score

    The goal is to find the sequence with the highest score after exploring all options.
  2. Step 2: Choose the best sequence after full exploration

    Collecting all sequences and their scores allows selecting the best one reliably.
  3. Final Answer:

    After collecting all sequences and scores, select the sequence with the highest score -> Option D
  4. Quick Check:

    Best score selection after exploration = A [OK]
Hint: Explore all, then pick highest score [OK]
Common Mistakes:
  • Choosing first sequence without comparison
  • Ignoring scores
  • Stopping early and missing better options