Tensorum
YouTubeகற்கத் தொடங்குங்கள்

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(&#39;inf')):
                dist[v] = nd
                heapq.heappush(pq, (nd, v))
    return dist

Complexity

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 தேவை

அடையாளக் குறிப்புகள்

DFS/BFSDSUTopological SortShortest PathMSTSCCBridgesEulerianGraph DP