What is a Graph?
A Graph is a non-linear data structure consisting of a finite set of Vertices (Nodes) and a set of Edges that connect these vertices. Graphs are used to model pairwise relations between objects, such as social networks, computer networks, and maps.
Time Complexity
- Adjacency Matrix (Search)O(1)
- Adjacency List (Search)O(V)
- BFS TraversalO(V + E)
- DFS TraversalO(V + E)
Key Concepts
- ✓Directed vs UndirectedDirected graphs have edges with direction (one-way), while Undirected graphs have bidirectional edges (two-way).
- ✓BFS vs DFSBFS explores neighbors layer by layer (Shortest Path). DFS explores as deep as possible before backtracking (Maze Solving).