ADVANCEDFrequently Tested 4 min read 3 views
Famous Algorithms & Proofs: Max-Flow Min-Cut, Huffman Trees, Kadane, Edit Distance & Cycle Detection
Ford-Fulkerson residual networks & Edmonds-Karp O(VE^2) bound, Max-Flow Min-Cut theorem, Huffman optimal prefix code tree properties, Kadane O(n) subarray, Levenshtein DP, and Floyd cycle pointer math.
1. Network Flow: Residual Graphs, Augmenting Paths & Min-Cut
- Ford-Fulkerson Method: Repeatedly finds an path in the Residual Graph (including backward edges that allow "undoing" earlier greedy flow!). On integer capacities, runtime can be pseudo-polynomial; choosing shortest augmenting paths via BFS (Edmonds-Karp) guarantees strongly polynomial !
2. Three Must-Know Linear & DP Algorithmic Gems
- Kadane’s Maximum Contiguous Subarray ( time, space):
- Edit (Levenshtein) Distance
dp[i][j](): Minimum insertions, deletions, and substitutions to convert into : - Floyd’s Tortoise & Hare Cycle Detection + Boyer-Moore Majority Vote ( time, space):
- Floyd’s Cycle: Slow moves step, Fast moves steps. Once they meet inside a cycle of length , resetting one pointer to
headand advancing both step at a time meets at the exact cycle entry node! - Boyer-Moore Majority ( occurrences): Pairwise cancel distinct elements using
(candidate, count)in pass + verification pass!
- Floyd’s Cycle: Slow moves step, Fast moves steps. Once they meet inside a cycle of length , resetting one pointer to
Key Formulas Summary
Max-Flow Min-Cut Theorem & Edmonds-Karp Complexity
Note: Net flow across ANY s-t cut equals |f|, while capacity c(S,T) counts ONLY forward edges S -> T!
Huffman Prefix Tree Weighted External Path Length & Node Count
Note: Every Huffman tree is a FULL binary tree (every internal node has degree 2; n leaves => n-1 merges)!
#Algorithms#Max Flow Min Cut#Huffman Coding#Kadane#Edit Distance#Floyd Cycle Detection
Practice Questions on This Chapter (2)
Q1GATE CS 2021NATMEDIUM
+2M • 0 Neg
Five characters a, b, c, d, e occur with frequencies 10, 15, 12, 3, 4 respectively in a file. What is the total number of bits needed to encode the file using an optimal Huffman prefix code?
Q2GATE CS 2023NATEASY
+1M • 0 Neg
Using Kadane’s Algorithm, what is the maximum contiguous subarray sum of the array [-2, 1, -3, 4, -1, 2, 1, -5, 4]?