Graph
BFS/DFS, topological sort, shortest paths, MST, union-find, bridges और SCCs — पढ़ाई के क्रम में।
DSAएडवांस्ड69 घंटे25 पैटर्न · 96 प्रॉब्लम
0%
आपकी प्रगतिप्रॉब्लम और केस स्टडी के नाम, कोड और तकनीकी कीवर्ड अंग्रेज़ी में ही रखे गए हैं।
मूल विचार
Unweighted shortest paths के लिए BFS, non-negative weights के लिए Dijkstra, dependencies के लिए topological sort, dynamic connectivity के लिए DSU, bridges और SCCs के लिए Tarjan।
कब इस्तेमाल करें
- Grids, dependencies, networks, word ladders
- Shortest path, connectivity, ordering, cycles
- 'States' और 'moves' वाली कोई भी चीज़ (state-space BFS)
टेम्पलेट
import heapq
def dijkstra(adj, src):
dist = {src: 0}
pq = [(0, src)]
while pq:
d, u = heapq.heappop(pq)
if d > dist.get(u, float('inf')):
continue
for v, w in adj[u]:
nd = d + w
if nd < dist.get(v, float('inf')):
dist[v] = nd
heapq.heappush(pq, (nd, v))
return distComplexity
BFS/DFS O(V + E); Dijkstra O(E log V); DSU प्रति operation ~O(α(n))।
आम गलतियाँ
- BFS में push की जगह pop पर visited चिह्नित करना (duplicates)
- Negative edges के साथ Dijkstra
- Directed और undirected cycle detection को अलग logic चाहिए
इस कोर्स के पैटर्न
Graph Fundamentals / BFS · 3Graph Fundamentals / DFS · 10Graph Fundamentals / DFS + DSU · 1Multi-Source BFS · 6State-Space BFS · 8Cycle Detection · 4Bipartite / 2-Coloring · 2Topological Sort / DAG · 10State-Space / Transformation BFS · 4Shortest Path / BFS-DAG · 2Shortest Path / Dijkstra · 7Shortest Path / 0-1 BFS · 2Shortest Path / Bellman-Ford · 1Shortest Path / Floyd-Warshall · 1Minimum Spanning Tree · 6Union Find / DSU · 12Eulerian Path / Circuit · 3Bridges / Articulation Points · 2Strongly Connected Components · 1Strongly Connected / Functional Graph · 2Graph DP · 2Graph / Transitive Closure · 1Shortest Path / BFS-Dijkstra · 2Graph Fundamentals / DFS-BFS · 3Shortest Path / BFS · 1
पहचान के संकेत
DFS/BFSDSUTopological SortShortest PathMSTSCCBridgesEulerianGraph DP