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 ಪ್ರತಿ op ಗೆ ~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