Graph theory is the study of graphs. A graph is a mathematical structure modeling pairwise relations between objects. In computer science, graphs represent networks, state machines, routing protocols, and data organization.
A graph $G$ is a pair $(V, E)$:
An edge connecting vertices $u$ and $v$ is denoted as $e = {u, v}$.
| Type | Description | Example |
|---|---|---|
| Undirected Graph | Edges have no orientation. A connection between $u$ and $v$ goes both ways. | Two-way roads |
| Directed Graph (Digraph) | Edges have a specific direction, pointing from a source vertex to a destination vertex. | One-way streets, web page links |
| Weighted Graph | Each edge has an assigned numerical weight or cost. | Distance maps, network routing tables |
| Complete Graph | Every pair of distinct vertices is connected by a unique edge. | Peer-to-peer networks |
| Bipartite Graph | Vertices divide into two disjoint sets where every edge connects a vertex in one set to a vertex in the other. | Job matching configurations |
A tree is a connected acyclic undirected graph. A directed acyclic graph is a DAG. Trees function as a foundational data structure in computer science.