Published by Patrick Mutisya · 8 days ago
Show understanding of how graphs can be used to aid Artificial Intelligence (AI).
Two common ways to store a graph in a computer program are:
| Representation | Structure | Typical Use‑case in AI |
|---|---|---|
| Adjacency Matrix | A two‑dimensional \$|V| \times |V|\$ array \$M\$ where \$M_{ij}=1\$ if an edge \$(i,j)\$ exists, otherwise \$0\$. | Dense graphs, quick edge‑existence checks (e.g., board games with many possible moves). |
| Adjacency List | An array of lists; each list \$L_i\$ contains all vertices adjacent to vertex \$i\$. | Sparse graphs, path‑finding in maps, knowledge‑base navigation. |
AI agents often need to find a path from a start state \$s\$ to a goal state \$g\$. The choice of algorithm depends on the graph’s properties and the problem requirements.
A heuristic \$h(n)\$ provides domain‑specific knowledge to guide search. Good heuristics are:
| Application | Graph Model | Typical Algorithm |
|---|---|---|
| Path‑finding in games (e.g., navigation meshes) | Weighted grid or navigation graph where vertices are walkable positions. | A* with Euclidean distance heuristic. |
| Knowledge representation (semantic networks) | Directed graph where concepts are vertices and relationships are labelled edges. | DFS/BFS for inference, shortest‑path for similarity measures. |
| Robot motion planning | Configuration space graph; each vertex is a robot pose. | Dijkstra or A* with obstacle‑avoidance heuristics. |
| Game tree search (e.g., chess) | Tree‑like directed graph where each node is a board state. | Minimax with alpha‑beta pruning (a specialised depth‑first search). |
| Strategy | Completeness | Optimality | Time Complexity | Space Complexity |
|---|---|---|---|---|
| DFS | No (may get stuck in loops) | No | \$O(b^m)\$ | \$O(bm)\$ |
| BFS | Yes (if branching factor finite) | Yes (un‑weighted) | \$O(b^d)\$ | \$O(b^d)\$ |
| Dijkstra | Yes | Yes (non‑negative weights) | \$O(|E| \log |V|)\$ | \$O(|V|)\$ |
| A* | Yes (if \$h\$ admissible) | Yes (if \$h\$ admissible) | Depends on \$h\$; worst‑case \$O(b^d)\$ | \$O(|V|)\$ |
Graphs provide a versatile framework for representing AI problems. By modelling states as vertices and actions as edges, AI algorithms can systematically explore solution spaces. Search techniques such as BFS, DFS, Dijkstra’s algorithm, and A* exploit graph structures to achieve completeness, optimality, or efficiency depending on the problem’s requirements. Understanding how to choose an appropriate representation and algorithm is essential for designing effective AI solutions at A‑Level.