πΈοΈ Graph Visualization (Click a node!)
Selected
Neighbor
Normal
π Current Graph Properties
Vertices
6
Edges
9
Type
Undirected
Weighted
Yes
Connected
Yes
Density
0.60
π Graph Terminology Dictionary (Click to visualize)
Vertex (Node)
A fundamental unit of a graph, representing an entity or data point
Edge (Link)
A connection between two vertices; may have weight or direction
Adjacent
Two vertices connected directly by an edge are adjacent
Degree
Number of edges connected to a vertex (in-degree / out-degree for directed)
Path
A sequence of vertices connected by edges with no repeated vertices
Cycle
A path that starts and ends at the same vertex, forming a loop
Connected
A graph where a path exists between every pair of vertices
Weight
A numerical value assigned to an edge representing cost or distance
Directed
Edges have a specific direction from source to destination
Component
A maximal connected subgraph where every vertex is reachable from every other
π Concept Guide
π What is a Graph?
A Graph is a non-linear data structure consisting of vertices (nodes) and edges (links) connecting pairs of vertices.
π‘ Formal Definition:
G = (V, E) where:
β’ V = set of vertices {vβ, vβ, ..., vβ}
β’ E = set of edges {(u,v) | u,v β V}
β’ Unlike trees, graphs can have cycles and multiple paths
G = (V, E) where:
β’ V = set of vertices {vβ, vβ, ..., vβ}
β’ E = set of edges {(u,v) | u,v β V}
β’ Unlike trees, graphs can have cycles and multiple paths
Graph vs Tree
| Feature | Tree | Graph |
|---|---|---|
| Cycles | Not allowed | Allowed |
| Root node | Has one root | No root concept |
| Edges | Exactly N-1 | Any number |
| Direction | Parent β Child | Optional |
| Connection | Always connected | Can be disconnected |
π Analogy
Think of a city map! Cities are vertices, roads are edges. Roads can be one-way (directed) or two-way (undirected), and have distances (weights).
π Mathematical Properties
| Property | Formula |
|---|---|
| Max edges (undirected) | V(V-1)/2 |
| Max edges (directed) | V(V-1) |
| Sum of all degrees | 2 Γ |E| (undirected) |
| Density | 2|E| / V(V-1) |
| Tree condition | |E| = |V| - 1 + connected |
π Handshaking Lemma:
The sum of all vertex degrees = 2 Γ number of edges.
Example: 9 edges β sum of degrees = 18
The sum of all vertex degrees = 2 Γ number of edges.
Example: 9 edges β sum of degrees = 18
β±οΈ Complexity by Representation
| Operation | Adj. Matrix | Adj. List |
|---|---|---|
| Check edge exists | O(1) | O(deg) |
| Get all neighbors | O(V) | O(deg) |
| Add edge | O(1) | O(1) |
| Remove edge | O(1) | O(deg) |
| Space | O(VΒ²) | O(V+E) |
π Types of Graphs
| Type | Description |
|---|---|
| Undirected | Edges have no direction; (u,v) = (v,u) |
| Directed (Digraph) | Edges have direction; (uβv) β (vβu) |
| Weighted | Edges carry numerical values (cost/distance) |
| Unweighted | All edges are treated equally |
| Connected | Path exists between every pair of vertices |
| Disconnected | Some vertices are unreachable from others |
| Cyclic | Contains at least one cycle |
| Acyclic (DAG) | No cycles; Directed Acyclic Graph |
| Complete (Kn) | Every vertex connects to every other vertex |
| Bipartite | Vertices split into two disjoint sets; edges only between sets |
| Sparse | |E| much less than |V|Β² β use Adjacency List |
| Dense | |E| close to |V|Β² β use Adjacency Matrix |
π‘ DAG (Directed Acyclic Graph):
Used in task scheduling, dependency resolution, build systems (Makefile, npm), and version control (Git commit history).
Used in task scheduling, dependency resolution, build systems (Makefile, npm), and version control (Git commit history).
π Real-World Applications
- Social Networks β Friend connections (Facebook, LinkedIn, Instagram)
- GPS / Maps β Shortest path navigation (Google Maps, Waze)
- Internet β Web page links (PageRank), network routing
- Recommendations β Netflix, Amazon, Spotify suggestions
- Package Managers β Dependency resolution (npm, pip, Maven)
- Compilers β Control flow graphs, syntax trees, call graphs
- Biology β Protein interactions, neural networks, gene regulation
- Transportation β Flight routes, railway networks, delivery optimization
- AI / ML β Knowledge graphs, graph neural networks (GNN)
- Blockchain β Transaction graphs, DAG-based ledgers
Data Structure Hierarchy:
β’ Array/List β 1D sequential data
β’ Tree β Hierarchical (1 parent per node)
β’ Graph β Complex relationships (any-to-any connections)
β’ Array/List β 1D sequential data
β’ Tree β Hierarchical (1 parent per node)
β’ Graph β Complex relationships (any-to-any connections)
π― Selected Node Info
π Click a node
Click a node in the graph to display its detailed information.
π Graph Mode
π¦ Highlight by Term
πΎ Graph Representations
// Adjacency Matrix (Weighted)
// A B C D E F
A [ 0 4 2 0 0 0 ]
B [ 4 0 1 5 0 0 ]
C [ 2 1 0 8 10 0 ]
D [ 0 5 8 0 2 6 ]
E [ 0 0 10 2 0 3 ]
F [ 0 0 0 6 3 0 ]
// 0 means no edge exists
// Space: O(VΒ²) = O(36)
// Adjacency List (Weighted)
A β [B:4] β [C:2]
B β [A:4] β [C:1] β [D:5]
C β [A:2] β [B:1] β [D:8] β [E:10]
D β [B:5] β [C:8] β [E:2] β [F:6]
E β [C:10] β [D:2] β [F:3]
F β [D:6] β [E:3]
// Space: O(V + 2E) = O(6+18)
// Edge List (src, dst, weight)
edges = [
(A, B, 4), (A, C, 2),
(B, C, 1), (B, D, 5),
(C, D, 8), (C, E, 10),
(D, E, 2), (D, F, 6),
(E, F, 3)
]
// Space: O(E) = O(9)
// Good for Kruskal's MST
π Key Formulas
Max edges (undirected)
V(V-1)/2Sum of degrees
2|E|Density
2E / V(V-1)Tree condition
E = V-1Complete graph edges
n(n-1)/2π Real-World Examples
Social Network β Friends & followers
Google Maps β Shortest path routes
Flight Routes β Airport connections
npm / pip β Package dependencies