Graph
A non-linear data structure consisting of a finite set of vertices (or nodes) and a set of edges connecting these vertices.
Traversal Visualizer
Goes as deep as possible before backtracking.
A
B
C
D
E
Order:
Types / Variants
Undirected Graph
Directed Graph
Weighted Graph
Unweighted Graph
Cyclic Graph
Acyclic Graph
Undirected Graph
Edges have no direction, representing a two-way relationship. If A is connected to B, B is also connected to A.
Complexity Analysis
| Operation | Time Complexity | Note |
|---|---|---|
| Add Vertex | O(1) | For adjacency list |
| Add Edge | O(1) | For adjacency list |
| Remove Vertex | O(V + E) | For adjacency list |
| Remove Edge | O(E) | For adjacency list |
| Search (DFS/BFS) | O(V + E) |
V = number of vertices, E = number of edges
When to Use Graphs
- Modeling networks: social networks, computer networks, road maps.
- Finding shortest paths (e.g., GPS navigation).
- Dependency resolution (e.g., course prerequisites, build systems).
- Web page crawling and search engine indexing.