Certainly!
Here's the complete, extra-detailed explanation of graph algorithms and
concepts, including theory, steps, and example problems with solutions.
GRAPH ALGORITHMS & CONCEPTS – DETAILED NOTES WITH EXAMPLES
1. Undirected Graphs, Biconnectivity, and Articulation Points
Undirected Graph
A graph where edges have no direction.
An edge (u, v) implies a bidirectional connection.
Degree of vertex: Number of incident edges.
Connectivity: A graph is connected if there's a path between any two vertices.
Biconnectivity
A graph is biconnected if removing any single vertex does not disconnect the graph.
Each biconnected component is a maximal biconnected subgraph.
Articulation Point
A vertex whose removal increases the number of connected components.
Found using DFS with discovery time and low value.
Algorithm:
1. Initialize disc[], low[], and parent[].
2. Run DFS:
o For each vertex u, for all children v:
If low[v] >= disc[u], then u is an articulation point.
Example:
Graph:
0—1—2
|
3
DFS traversal reveals:
disc[1] = 1, low[3] = 3
Since low[3] >= disc[1], vertex 1 is an articulation point.
2. Euler Circuits
Definition:
A Euler circuit visits every edge exactly once and returns to the starting vertex.
Condition:
The graph must be connected.
All vertices must have even degree.
Example:
Graph:
0—1
| |
3—2
All vertices have degree 2 ⇒ Eulerian.
One Euler circuit: 0 → 1 → 2 → 3 → 0.
3. Directed Graphs and Strongly Connected Components (SCCs)
Directed Graph:
Edges have directions: (u → v) ≠ (v → u).
Strongly Connected Component (SCC):
A maximal set of vertices where each is reachable from every other in the set.
Kosaraju’s Algorithm:
1. DFS on original graph → push nodes in finishing order.
2. Transpose graph.
3. DFS in order of stack → get SCCs.
Example:
Edges: A→B, B→C, C→A, B→D, D→E, E→F, F→D
SCCs:
o {A, B, C}
o {D, E, F}
4. Bellman-Ford Algorithm
Use:
Single Source Shortest Path, even with negative edge weights.
Steps:
1. Set dist[source] = 0, others to ∞.
2. Relax all edges V - 1 times.
3. Check for negative-weight cycles.
Time Complexity: O(V × E)
Example:
Graph:
0 → 1 (4)
0 → 2 (5)
1 → 2 (-3)
2 → 3 (4)
Start from vertex 0:
Iteration 1:
dist[0]=0, dist[1]=4, dist[2]=1, dist[3]=5
Final distances: 0→0, 1→4, 2→1, 3→5
5. Floyd-Warshall Algorithm (All-Pairs Shortest Paths)
Idea:
Dynamic programming approach to find shortest paths between all pairs.
Formula:
dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])
Time Complexity: O(V³)
Example:
Input graph:
dist = [[0, 3, ∞],
[∞, 0, 1],
[1, ∞, 0]]
Final distances:
[[0, 3, 4],
[2, 0, 1],
[1, 4, 0]]
6. Ford-Fulkerson Method (Maximum Flow)
Flow Network:
Directed graph where each edge has capacity and flow.
Ford-Fulkerson:
Find augmenting paths using BFS or DFS.
Update residual capacities.
Terminology:
Residual capacity = capacity - flow
Use residual graph for finding paths.
Time Complexity:
Naive: O(max_flow × E)
With BFS (Edmonds-Karp): O(V × E²)
Example:
s → a (10)
s → b (5)
a → b (15)
a → t (10)
b → t (10)
Path 1: s → a → t, flow = 10
Path 2: s → b → t, flow = 5
Max flow = 15
7. Maxflow-Mincut Theorem
Theorem:
The maximum flow from s to t is equal to the capacity of the minimum s-t cut.
Implications:
Optimality proof of max-flow algorithm.
Partition vertices into S and T such that:
o s ∈ S, t ∈ T
o Cut capacity = sum of capacities of edges from S to T.
Example:
In the previous network, cut between s and {a, b, t} yields capacity:
s → a (10), s → b (5) → Cut = 15
Matches Max Flow =
Summary Table
Concept Key Idea Time Complexity Example
Undirected Graph No edge direction — DFS
Biconnectivity No single vertex disconnects graph O(V + E) DFS Tree
Euler Circuit Visit all edges once, return O(E) Hierholzer
SCC (Kosaraju) Maximal strongly connected sets O(V + E) Stack + DFS
Bellman-Ford Single source, negative weights O(V × E) Relax edges
Floyd-Warshall All-pairs shortest path O(V³) DP
Ford-Fulkerson Max flow in flow network O(E × max_flow) Residual graph
Maxflow-Mincut Cut capacity = max flow — Partition
Would you like me to also include diagrams (e.g. residual graphs, DFS tree, SCC
component maps) in a downloadable format, or continue next with problems on Dijkstra,
Prim, Kruskal, or Topological Sort?