This interactive simulation introduces the fundamental concepts of Graph Theory, a branch of discrete mathematics that studies the relationships between objects. Graphs are used extensively in computer science, network analysis, social sciences, biology, and optimization problems.
E (Edges): A set of connections between pairs of vertices
Graphs model relationships such as: social networks (people connected by friendships), road maps (cities connected by roads), web pages (linked by hyperlinks), and molecular structures (atoms connected by bonds).
Graph Types
Type
Definition
Example
Undirected Graph
Edges have no direction. If A is connected to B, then B is also connected to A.
Friendship networks, road maps (two-way streets)
Directed Graph (Digraph)
Edges have direction (arrows). Edge from A to B doesn't imply edge from B to A.
Twitter followers, web links, one-way streets
Weighted Graph
Each edge has an associated numerical value (weight).
Every pair of distinct vertices is connected by an edge.
Full connectivity, round-robin tournaments
Graph Representations
There are several ways to represent graphs mathematically and in computer memory:
Representation
Description
Size
Adjacency Matrix (A)
V×V matrix where A[i][j] = 1 if edge exists from i to j, 0 otherwise. Symmetric for undirected graphs. For weighted graphs, stores edge weights.
O(V²)
Incidence Matrix (B)
V×E matrix where B[v][e] = 1 if vertex v is incident to edge e. For directed graphs: +1 if edge leaves v, -1 if edge enters v.
O(V×E)
Degree Matrix (D)
V×V diagonal matrix where D[i][i] = degree of vertex i. All off-diagonal entries are zero.
O(V²)
Laplacian Matrix (L)
L = D - A (Degree minus Adjacency). Key property: Row sums = 0. Used in spectral graph theory, graph partitioning, and network analysis.
O(V²)
Adjacency List
Array of lists where the i-th list contains all neighbors of vertex i. More space-efficient for sparse graphs.
O(V + E)
Laplacian Matrix Properties:
Always has at least one eigenvalue = 0
Number of zero eigenvalues = number of connected components
Second smallest eigenvalue (Fiedler value) measures graph connectivity
Used in: spectral clustering, graph partitioning, network flow analysis
Vertex Degree
The degree of a vertex is the number of edges connected to it:
Undirected Graph: deg(v) = number of edges incident to v
Directed Graph:
• in-degree(v) = number of edges pointing TO v
• out-degree(v) = number of edges pointing FROM v
Handshaking Lemma: In any undirected graph, the sum of all vertex degrees equals twice the number of edges:
Σ deg(v) = 2|E|
Special Vertices
Isolated Vertex: A vertex with degree 0 (no edges)
Pendant/Leaf: A vertex with degree 1 (exactly one edge)
Hub/Celebrity: A vertex with very high degree relative to others
Graph Isomorphism
Two graphs G₁ and G₂ are isomorphic if there exists a one-to-one mapping between their vertices that preserves edge connections. In other words, they have the same structure but may look different when drawn.
Quick Check for Isomorphism:
If two graphs are isomorphic, they must have:
Same number of vertices
Same number of edges
Same degree sequence (sorted list of degrees)
However, matching these conditions doesn't guarantee isomorphism!
Common Graph Structures
Structure
Definition
Properties
Path (Pn)
n vertices connected in a line
n-1 edges, 2 leaves, no cycles
Cycle (Cn)
n vertices forming a closed loop
n edges, every vertex has degree 2
Star (Sn)
One central vertex connected to n-1 others
n-1 edges, 1 hub with degree n-1
Complete (Kn)
Every vertex connected to every other
n(n-1)/2 edges, every vertex has degree n-1
Bipartite
Vertices split into two groups, edges only between groups
No odd cycles, 2-colorable
Binary Tree
Hierarchical structure where each node has at most 2 children
n-1 edges for n nodes, no cycles, connected
Grid/Mesh
Nodes arranged in rows and columns with neighbors connected
Regular structure, used in image processing, routing
Petersen Graph
Famous 10-vertex graph: outer pentagon + inner pentagram with spokes
3-regular (every vertex has degree 3), non-planar, highly symmetric
The Petersen Graph: One of the most famous graphs in graph theory, often used as a counterexample. Properties:
3-regular: Every vertex has exactly 3 neighbors
Non-planar: Cannot be drawn without edge crossings
Girth 5: Smallest cycle has length 5
Diameter 2: Any two vertices are at most 2 steps apart