Graph algorithms formulas
Graphs: traversals, minimum spanning trees and shortest paths. 9 formulas for GATE CS, DA Data Structures and Algorithms, each with when to use it. Each is explained in the topic notes.
IAE Academy: Graphs: traversals, minimum spanning trees and shortest paths formulas (GATE CS, DA)
All 9 Graph algorithms formulas
Space cost of the two representations
Use the matrix when the graph is dense (E close to V^2) or constant-time edge checks are needed; use the list when the graph is sparse (E much smaller than V^2). An undirected graph's adjacency lists hold 2E entries in total (each edge appears in both endpoints' lists); a directed graph's hold E.
Handshake lemma and edge bounds (simple graphs)
The degree sum counts every undirected edge once from each end. Consequence: every undirected graph has an even number of odd-degree vertices. In a directed graph, the sum of in-degrees = the sum of out-degrees = E.
Parenthesis theorem (for two vertices with d[u] < d[v])
Exactly one of the two holds. The first means v is a descendant of u in the DFS forest (the intervals are nested). The second means neither is a descendant of the other (the intervals are disjoint). Partial overlap, d[u] < d[v] < f[u] < f[v], is impossible.
Number of edges in a spanning tree or forest
The first holds for any spanning tree of a connected graph on V vertices, whatever the weights. The second is for a graph with k connected components, where Kruskal run to completion produces a minimum spanning forest.
Number of labelled spanning trees of the complete graph K_n
For example, K_4 has 4^2 = 16 spanning trees. This counts spanning trees, not MSTs; with distinct weights, exactly one of them is the MST.
Dijkstra's time complexity
Correctness is guaranteed only when all edge weights are non-negative. The array version suits dense graphs (E close to V^2); the binary-heap version suits sparse graphs (E much smaller than V^2).
Bellman-Ford's time complexity
Each of the V−1 rounds scans all E edges once; the extra negative-cycle check costs another O(E).
Floyd-Warshall recurrence
d_k[i][j] is the length of the shortest path from i to j whose intermediate vertices all lie in {1,...,k}. d_0 is the input: d_0[i][i] = 0, d_0[i][j] = w(i,j) where a direct edge exists, and infinity otherwise. The answer is d_V.
Floyd-Warshall complexity
Three nested loops over all V vertices. It is correct with negative edge weights as long as there is no negative-weight cycle, and it detects one if present. Replacing min with OR and + with AND gives the transitive-closure (reachability) algorithm, also O(V^3).
Where this was asked: 2018 (2), 2020 (3), 2022 (1), 2023 (1), 2024 (6), 2025 (8), 2026 (7). See the 28 previous-year questions on Graph algorithms. This shows what was asked, not what will be asked.