graph = {
0: [1, 2],
1: [0, 3],
2: [0, 3],
3: [1, 2, 4],
4: [3]
}
Space: O(V + E)
Add edge: O(1)
Check edge: O(degree)
Iterate neighbors: O(degree)
✅ Best for sparse graphs
✅ BFS, DFS, Dijkstra
mat = [ [0,1,1,0,0], [1,0,0,1,0], [1,0,0,1,0], [0,1,1,0,1], [0,0,0,1,0] ] Space: O(V²) Add edge: O(1) Check edge: O(1) ⚡ Iterate neighbors: O(V) ✅ Best for dense graphs ✅ Floyd-Warshall