Tree DP and Path Problems: Maximum Path Sum, Diameter, LCA, and Serialization (2025)
6 min read Tree DP Pattern Many tree problems require computing an answer that depends on both subtrees. The key pattern: define a […] Read article
Master fundamental and advanced algorithms essential for technical interviews at top companies. This category covers sorting algorithms, search algorithms, graph algorithms, and optimization techniques that form the foundation of computer science problem-solving.
What You’ll Learn:
Sorting algorithms: Quick sort, merge sort, heap sort
Search techniques: Binary search and variations
Graph algorithms: DFS, BFS, Dijkstra’s, topological sort
Optimization: Dynamic programming, greedy algorithms
Time and space complexity analysis
Difficulty Progression: Start with basic sorting and searching, then progress to graph algorithms and dynamic programming.
Interview Frequency: Extremely high – algorithms appear in 80%+ of technical interviews at Google, Amazon, Facebook, Microsoft, and Apple.
6 min read Tree DP Pattern Many tree problems require computing an answer that depends on both subtrees. The key pattern: define a […] Read article
6 min read What Makes an Algorithm Greedy A greedy algorithm makes the locally optimal choice at each step, hoping this leads to Read article
6 min read Palindrome Check A palindrome reads the same forward and backward. Brute force check: O(n). Two-pointer: left=0, right=n-1; while left < Read article
6 min read The String Matching Problem Given a text T of length n and a pattern P of length m, find all Read article
6 min read Topological Sort A topological ordering of a directed acyclic graph (DAG) is a linear ordering of vertices such that for Read article
5 min read When Number Theory Appears in Interviews Number theory problems appear in interviews at companies like Google, Facebook, and competitive programming Read article
7 min read What Is a Minimum Spanning Tree? A Minimum Spanning Tree (MST) of a weighted undirected graph is a spanning tree Read article
5 min read Choosing the Right Algorithm Decision tree: non-negative weights? -> Dijkstra (O((V+E) log V)). Negative weights, no negative cycles? -> Bellman-Ford Read article
6 min read Monotonic Stack Concept A monotonic stack maintains elements in strictly increasing or decreasing order. Elements that violate the order are Read article
6 min read What Is Amortized Analysis? Amortized analysis gives the average cost per operation over a sequence of operations, even when individual Read article
6 min read Why Randomized Algorithms? Randomized algorithms use random choices to achieve good expected performance, simplify implementation, or avoid worst-case inputs that Read article
7 min read When to Use DP on Graphs DP on graphs works when the graph has structure that prevents cycles in the Read article
7 min read Naive String Matching For each position i in text (0 to n-m): check if text[i:i+m] == pattern. O(n*m) in the Read article
7 min read Bellman-Ford Algorithm Finds shortest paths from a source to all nodes, handling negative edge weights. Algorithm: initialize dist[source]=0, dist[all others]=inf. Read article
5 min read GCD and LCM Greatest Common Divisor (GCD): the largest number that divides both a and b. Euclidean algorithm: gcd(a, b) Read article