- Graphs: how they help AI
Nodes joined by edges model states and routes that AI can search.
A graph is a data structure made up of:
- Nodes (also called vertices) — points that represent a state or object (e.g. a town, a junction, a position in a game).
- Edges — connections that join two nodes (e.g. a road between two towns).
A weighted graph adds a number (a weight) to each edge, representing a cost such as distance, travel time or price.
| Term | Meaning |
|---|---|
| Node / vertex | a point (a state or object) |
| Edge | a connection between two nodes |
| Weight | a numeric cost on an edge |
Why graphs help AI. Many AI problems are really about finding the best path through a set of possibilities — the shortest route on a map, the cheapest sequence of moves, the quickest way from one state to a goal state. A graph captures which states are connected and how costly each connection is, so a search algorithm can explore it efficiently and return the lowest-cost path.
Here is a small weighted graph (the one used in the worked example). Each circle is a node; each line is an edge labelled with its weight:
- Graph = nodes (vertices) joined by edges.
- Weighted graph = each edge carries a numeric cost.
- AI models states/routes as graphs so they can be searched.
- The search returns the lowest-cost (shortest) path.