---
obj: concept
wiki: https://en.wikipedia.org/wiki/Graph_theory
rev: 2024-04-10
---

# Graph Theory
In mathematics, graph theory is the study of graphs, which are mathematical structures used to model pairwise relations between objects. A graph in this context is made up of vertices (also called nodes or points) which are connected by edges (also called arcs, links or lines). A distinction is made between undirected graphs, where edges link two vertices symmetrically, and directed graphs, where edges link two vertices asymmetrically.

## Graph
A graph $G$ consists of a set of vertices $V$ and a set of edges $E$, where each edge is a pair of vertices. Formally, we can represent a graph as $G=(V,E)$.

### Types of Graphs
1. **Undirected Graph**: In an undirected graph, edges have no direction. If there is an edge between vertex $A$ and vertex $B$, it means $A$ is adjacent to $B$, and $B$ is adjacent to $A$.
2. **Directed Graph (Digraph)**: In a directed graph, edges have a direction. If there is an edge from vertex $A$ to vertex $B$, it means $A$ is adjacent to $B$, but not necessarily vice versa.
3. **Weighted Graph**: In a weighted graph, each edge has an associated weight or cost.
4. **Cyclic Graph**: A graph that contains a cycle, i.e., a sequence of vertices where a vertex is reachable from itself by following the edges.
5. **Acyclic Graph**: A graph that contains no cycles.
6. **Disconnected Graph**: A graph with loose vertices.
    
### Graph Representation
Graphs can be represented using various data structures such as adjacency matrix, adjacency list, and incidence matrix.

- **Adjacency Matrix**: A two-dimensional array where the value of $A[i][j]$ indicates whether there is an edge between vertices $i$ and $j$. This representation is suitable for dense graphs.
- **Adjacency List**: A collection of lists or arrays where each list represents the vertices adjacent to a particular vertex. This representation is efficient for sparse graphs.
- **Incidence Matrix**: A two-dimensional array where rows represent vertices and columns represent edges. Each entry $M[i][j]$ indicates whether vertex $i$ is incident to edge $j$.

### Graph Operations
- **Add Vertex**: Adding a new vertex to the graph.
- **Add Edge**: Adding a new edge between two vertices.
- **Remove Vertex**: Removing a vertex from the graph along with its incident edges.
- **Remove Edge**: Removing an edge from the graph.
- **Traversal**: Visiting all vertices or edges of the graph in a systematic way.

### Graph Traversal
- **Depth-First Search (DFS)**: A graph traversal algorithm that explores as far as possible along each branch before backtracking. DFS can be used to traverse both directed and undirected graphs.
- **Breadth-First Search (BFS)**: A graph traversal algorithm that explores all the neighbor vertices at the present depth prior to moving on to the vertices at the next depth level. BFS can be used to find the shortest path in unweighted graphs.

### Graph Algorithms
- **Shortest Path Algorithms**: Algorithms to find the shortest path between two vertices in a graph, such as Dijkstra's algorithm for non-negative edge weights and Bellman-Ford algorithm for graphs with negative edge weights.
- **Minimum Spanning Tree (MST)**: Algorithms to find a subset of edges that connect all the vertices in the graph with the minimum total edge weight. Prim's algorithm and Kruskal's algorithm are commonly used for finding MSTs.
- **Topological Sorting**: An ordering of the vertices of a directed graph such that for every directed edge $(u,v)$, vertex $u$ comes before vertex $v$ in the ordering. This is useful in scheduling tasks with dependencies.
- **Graph Coloring**: Assigning colors to the vertices of a graph such that no two adjacent vertices have the same color. Graph coloring is used in register allocation in compilers, scheduling problems, and map coloring.

## Applications of Graph Theory
Graph theory finds applications in various fields including:

- **Computer Science**: Graph algorithms are used in networking, data compression, and optimization problems.
- **Social Network Analysis**: Graphs can model relationships between individuals in social networks.
- **Transportation Networks**: Graphs are used to represent road networks, flight routes, and public transportation systems.
- **Biology**: Graphs are used to model genetic networks, protein-protein interactions, and ecological systems.
- **Operations Research**: Graphs are used to model and solve problems in logistics, supply chain management, and scheduling.
