tinycodinglm / math /math-0174.jsonl
winapiadmin's picture
Upload folder using huggingface_hub (part 16)
d517dc9 verified
|
Raw History Blame Contribute Delete
1.02 kB
opencode trace
System You are an expert mathematician and programmer.

You are an expert mathematician and programmer.

User

Explain graph theory algorithms for competitive programming

Assistant

BFS: shortest path unweighted. O(V+E). Queue-based layer-by-layer.
DFS: cycle detection, connected components, topological sort, articulation points, bridges.
Dijkstra: shortest path non-negative weights. O((V+E) log V) with min-heap.
Bellman-Ford: shortest path with negative weights. O(VE). Relax all edges V-1 times.
Floyd-Warshall: all-pairs shortest paths. O(V^3). dp[k][i][j] = min path i to j using 1..k.
Kruskal: MST. Sort edges O(E log E), union-find. Prim: MST. O((V+E) log V) with PQ.
Topological sort: Kahn's BFS with in-degree or DFS post-order reverse.
SCC: Tarjan's or Kosaraju's O(V+E).