Home / Blog /

AO* Algorithm in AI

Heuristic Search for AND-OR Graphs

Uncodemy AI Team
June 21, 2026
15 min read
Scroll Down

AO* Algorithm

Overview of AO* Algorithm

Discuss the AO* algorithm with example.

Answer:

The AO* algorithm is a heuristic search algorithm designed for AND-OR graphs, commonly used in AI for problems where solutions involve AND and OR relationships, such as planning and problem decomposition. Unlike A*, which operates on OR graphs, AO* handles nodes with AND arcs (all successors must be solved) and OR arcs (at least one successor must be solved). It maintains a dynamic cost estimate and updates the graph as it explores. Below, we explain AO*’s mechanics, properties, and an example using a problem-solving AND-OR graph, addressing loop prevention.

Mechanics of AO* Algorithm
  • Initialization: Start with the root node in an AND-OR graph, assign initial heuristic costs (h(n)).
  • Exploration: Select the most promising node using f(n) = g(n) + h(n), where g(n) is the cost to reach the node, and h(n) is the heuristic cost to the goal. Expand AND or OR successors.
  • Cost Update: Propagate costs backward, updating parent nodes based on AND (sum of successor costs) or OR (minimum successor cost) relationships.
  • Termination: Stop when the root is marked “solved” or no solution exists.
  • Loop Prevention: Track visited nodes and avoid re-expanding solved subtrees to prevent cycles.
Properties
  • Completeness: Guaranteed in finite AND-OR graphs with loop prevention.
  • Optimality: Finds the optimal solution if h(n) is admissible (never overestimates).
  • Time Complexity: Depends on graph size and heuristic quality, typically O(b^d) in worst case.
  • Space Complexity: O(b^d) for storing the graph and priority queue.
Example: Problem Decomposition

Consider a problem where the goal is to solve a task A, which can be decomposed into subtasks:
- A can be solved by (B AND C) OR D.
- B requires E AND F.
- C, D, E, F are terminal nodes with costs: h(C)=3, h(D)=4, h(E)=2, h(F)=1.

Execution:
- Start at A: Assume initial h(A)=4 (OR arc: min(h(B AND C), h(D))).
- Expand A: OR arc to D (h=4) or AND arc to B,C (h(B AND C)=h(B)+h(C)).
- Expand B: AND arc to E,F. h(B)=h(E)+h(F)=2+1=3. h(B AND C)=3+3=6.
- Choose D (f(D)=4 < f(B AND C)=6). Mark D as solved.
- Backtrack to A: A is solved via D (cost=4).
Solution: A → D (cost=4).

Loop Prevention: A visited set prevents re-expansion of solved nodes (e.g., D), avoiding cycles in the graph.

Understanding AO* Algorithm

AO* is tailored for AND-OR graphs, making it ideal for problems involving task decomposition, planning, and decision-making in AI. It dynamically updates costs to find optimal solutions.

Key Insight

AO* Algorithm handles AND-OR relationships, ensuring optimal solutions for complex problem structures.

Real-World Example: In robotic planning, AO* decomposes tasks like “move to location” into subtasks (e.g., “navigate AND avoid obstacles”).

Did You Know?

AO* is used in AI planning systems for robotics and expert systems.

Comparing AO* Algorithm

The textual diagram below compares AO* with other search algorithms.

Exploring AO* Algorithm

Below, we explore AO* and related algorithms with vibrant cards.

AO* Search

Optimal for AND-OR graphs, ideal for planning and decomposition.

A* Search

Optimal for OR graphs, widely used for pathfinding.

Best-First Search

Greedy, prioritizes h(n), faster but non-optimal.

AO* Algorithm: Python Code

Below is a simplified Python implementation of AO* for the example AND-OR graph.

from heapq import heappush, heappop

graph = {
    'A': [('B', 'C', 0), ('D', 0)],  # (B AND C) OR D
    'B': [('E', 'F', 0)],            # E AND F
    'C': [], 'D': [], 'E': [], 'F': []
}
heuristics = {'A': 4, 'B': 3, 'C': 3, 'D': 4, 'E': 2, 'F': 1}
and_nodes = {('B', 'C'), ('E', 'F')}

def ao_star():
    frontier = [(heuristics['A'], 'A', [])]  # (f(n), node, path)
    solved = set()
    costs = heuristics.copy()
    
    while frontier:
        _, current, path = heappop(frontier)
        if current in solved:
            continue
        if not graph[current]:  # Terminal node
            solved.add(current)
            continue
        
        # Expand node
        for successors in graph[current]:
            cost = 0
            if len(successors) > 1:  # AND arc
                cost = sum(costs[n] for n in successors)
                if all(n in solved for n in successors):
                    solved.add(current)
            else:  # OR arc
                cost = costs[successors[0]]
                if successors[0] in solved:
                    solved.add(current)
            
            costs[current] = min(costs.get(current, float('inf')), cost)
            for succ in successors:
                if succ not in solved:
                    heappush(frontier, (costs[succ], succ, path + [current]))
        
        if 'A' in solved:
            return path + ['A']
    
    return None

path = ao_star()
print("Solution Path:", path if path else "No solution")
                    

This code finds the optimal solution A → D, using a visited set to prevent cycles.

Technical Insights for Students

Mastering AO* enhances your AI planning skills:

  • Heuristic Design: Use admissible heuristics for terminal nodes.
  • Loop Prevention: Track solved nodes to avoid redundant exploration.
  • Implementation: Manage AND-OR relationships with dynamic cost updates.
  • Practical Tip: Implement AO* for a planning problem in Colab to compare with A*.

Key Takeaways

  • AO* is optimal for AND-OR graphs, ideal for planning.
  • Handles AND and OR relationships with dynamic cost updates.
  • Loop prevention ensures termination.
  • Key for AI applications like robotics and expert systems.

Ready to Master AI Search Algorithms?

Join Uncodemy’s AI Certification Program to learn AO* and other techniques.

Start Learning Today

Uncodemy Learning Platform

Popular Courses

Uncodemy AI Expert

About the Author

Dr. Sarah Johnson is Uncodemy's lead AI instructor with 10+ years of experience in machine learning and neural networks. She has worked with leading tech companies and now focuses on training the next generation of AI professionals.