Graphs
Understand graph representations and algorithms
Graphs are versatile data structures consisting of vertices (nodes) and edges (connections). They model relationships and networks, from social connections to routing algorithms, making them essential for solving complex real-world problems.
Key Concepts
- Directed vs Undirected, Weighted vs Unweighted
- Representations: Adjacency Matrix, Adjacency List
- Traversals: BFS (shortest path), DFS (connectivity)
- Shortest path: Dijkstra, Bellman-Ford, Floyd-Warshall
- Minimum Spanning Tree: Prim's, Kruskal's algorithms
Problems
Number of Islands
MediumSoonCount connected components in 2D grid
DFSBFSUnion Find
Clone Graph
MediumSoonDeep copy an undirected graph
DFSBFSHash Map
Course Schedule
MediumSoonDetect cycle in directed graph (topological sort)
Topological SortDFS
Pacific Atlantic Water Flow
MediumSoonFind cells that can flow to both oceans
DFSMatrix
Network Delay Time
MediumSoonFind minimum time for signal to reach all nodes
DijkstraShortest Path