ABSTRACT
A graph is a mathematical structure used to model pairwise relations between objects. It consists of a set of vertices (nodes) and a set of edges connecting them. Graphs are fundamental to computer science, used in everything from network routing to social media analysis.
Types of Graphs
Directed Graphs
A directed graph (or digraph) consists of:
- A nonempty set of vertices .
- A set of directed edges . Each edge is an ordered pair , representing a one-way connection from vertex to vertex .
Undirected Graphs
An undirected graph consists of:
- A nonempty set of vertices .
- A set of undirected edges . Each edge is an unordered pair , representing a two-way connection between and .
Special Types of Undirected Graphs
Complete Graph ()
A complete graph is an undirected graph where every pair of distinct vertices is connected by a unique edge.
- Density: This is the densest possible simple graph.
- Edge Count: Since every vertex connects to every other vertex, the total edges are:

Bipartite Graph
A graph whose vertices can be divided into two disjoint sets and such that every edge connects a vertex in to one in .
- Constraint: No two vertices within the same set are adjacent.
- Use Case: Modeling relationships between two different categories (e.g., Students and Classes).
Trees
Trees are a highly restricted but extremely common subset of graphs.
Undirected Tree
An undirected graph that is connected and contains no cycles.
- See more: Undirected Trees
Directed Tree (Rooted Tree)
A directed graph where one vertex is the root (in-degree 0) and every other vertex has exactly one incoming edge (in-degree 1).
- See more: Directed Tree (Rooted Tree)
Simple Labeled Graphs
A graph is considered simple if it lacks the following complexities:
- Self-Loops: An edge that connects a vertex to itself.
- Parallel Edges: Multiple edges between the same two vertices (in the same direction for directed graphs).

Encoding Simple Directed Graphs
For vertices, each vertex can potentially point to any of the other vertices.
- Potential Edges:
- Total Possible Graphs:
- Bits Required: bits.
Encoding Simple Undirected Graphs
For vertices, an edge can exist between any unique pair of vertices.
- Potential Edges:
- Total Possible Graphs:
- Bits Required: bits.
Graph Representations
The choice of representation depends on the density of the graph (how many edges exist relative to the number of vertices).
| Representation | Memory Efficiency | Best Use Case | Graph for Best use Case |
|---|---|---|---|
| Adjacency Matrix | Dense Graphs (many edges) | ![]() | |
| Adjacency List | ![]() |
Adjacency Matrix
An matrix where the entry at row , column represents the connection from vertex to vertex .
- Simple Graphs: Entries are or .
- Parallel Edges: Entries can be integers .
- Self-Loops: Indicated by non-zero values on the main diagonal.
- Undirected Symmetry: In an undirected graph, the matrix is symmetric (), making the lower triangle a mirror of the upper triangle.
Adjacency List
A collection of lists where each vertex is associated with a list of its neighbors. In a directed graph, this usually stores outgoing neighbors.
- Adjacent: Two vertices connected by an edge are said to be adjacent.
- Neighbors (Undirected):
- Outgoing Neighbors (Directed):
- Incoming Neighbors (Directed):
Related Notes
- Graph Reachability: These structures determine how search algorithms (BFS/DFS) behave.
- Lossless Encoding: How we calculate the bits needed to store these specific graph types.
- Undirected Trees: Deep dive into the mathematical properties of acyclic connected graphs.

