Graph
BFS/DFS, topological sort, shortest paths, MST, union-find, bridges আর SCCs — পড়ার ক্রমে।
DSAঅ্যাডভান্সড69 ঘণ্টা25টি প্যাটার্ন · 96টি প্রবলেম
0%
আপনার অগ্রগতিপ্রবলেম ও কেস স্টাডির নাম, কোড আর প্রযুক্তিগত কীওয়ার্ড ইংরেজিতেই রাখা হয়েছে।
মূল ধারণা
Unweighted shortest path-এ BFS, non-negative weight-এ Dijkstra, dependency-তে 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 edge সহ 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