Networks of vertices and edges modeling complex relationships and pathways.
Theory
Code
Theory & Description
A graph consists of a set of vertices (nodes) connected by edges. Graphs can be directed or undirected, weighted or unweighted, and cyclic or acyclic. They model complex relationships like social networks, road maps, and dependency systems. Key traversal algorithms include Depth-First Search (DFS) and Breadth-First Search (BFS), while pathfinding uses Dijkstra's and Bellman-Ford algorithms.
Common Use Cases
- Social network connections
- Map routing and GPS navigation
- Dependency resolution in build systems
- Network topology and circuit analysis
Complexity Cheat Sheet
| Operation | Average | Worst |
|---|---|---|
| Add Vertex | O(1) | O(1) |
| Add Edge | O(1) | O(1) |
| BFS / DFS | O(V + E) | O(V + E) |
| Remove Vertex | O(V + E) | O(V + E) |
| Space Complexity | O(V + E) | |
Visualization
Problems
Interactive Visualization
Interactive Visualization
An interactive playground for Graphs will appear here. Insert elements, step through operations, and watch the data structure update in real time.