Tree Pruning and Deletion Patterns
Master tree pruning and deletion — delete nodes in BST, prune binary trees, trim BST to range, and remove leaves with a given value. Full Python implementations with Big-O analysis.
277 posts · page 3 of 6
Master tree pruning and deletion — delete nodes in BST, prune binary trees, trim BST to range, and remove leaves with a given value. Full Python implementations with Big-O analysis.
Solve all Path Sum variants — root-to-leaf existence, find all paths, any-to-any with prefix sums. Complete Python solutions with Big-O analysis.
Check if a tree is symmetric, whether one tree is a subtree of another, same tree comparison, and flip equivalence. Python solutions with analysis.
Master vertical order traversal with column-based grouping. Includes top view, bottom view, and vertical sum with Python solutions.
Master zigzag level-order traversal of binary trees using deque and flag toggling. Multiple Python approaches with step-by-step walkthrough.
Learn the A* search algorithm with f=g+h, admissible heuristics, grid pathfinding, and Python implementation compared to Dijkstra and BFS.
Find critical nodes and edges in graphs using Tarjan's algorithm with discovery and low-link arrays, with Python code and network applications.
Understand AVL trees — balance factors, all four rotation types (LL, RR, LR, RL), insertion with rebalancing, and complete Python implementation with height tracking.
Master backtracking with the choose-explore-unchoose template. Solve N-Queens, Sudoku, word search, generate parentheses, palindrome partitioning, and subset sum.
Convert sorted arrays and linked lists into balanced BSTs using divide and conquer. BST to sorted DLL, Day-Stout-Warren algorithm, and Python implementations.
Master binary lifting to answer Lowest Common Ancestor (LCA) and kth ancestor queries in O(log n) with O(n log n) preprocessing. Full Python implementations with tree examples.
Master binary search with three templates -- exact match, first/last true, and answer space search. Covers rotated arrays, peak elements, and common off-by-one mistakes.
Solve all binary tree view problems — left view, right view, top view, bottom view, and vertical order traversal. BFS-based Python implementations.
Master bitmask dynamic programming — represent subsets as integers, solve the Travelling Salesman Problem, assignment problem, and subset enumeration with Python implementations.
Master counting techniques for DSA: permutations, combinations, Pascal's triangle, Catalan numbers, inclusion-exclusion, pigeonhole principle, and modular arithmetic.
Master Binary Search Tree operations — insert, search, and all three delete cases with in-order successor. Full Python implementation with time complexity analysis.
Build a circular queue from scratch — understand ring buffers, front/rear pointer math with modulo, full vs empty detection, and real-world uses in OS scheduling.
Break the comparison sort barrier with counting sort, radix sort (LSD and MSD), and bucket sort — Python implementations, stability analysis, and when to use each non-comparison sort.
Master doubly linked lists with prev/next pointers, insertion and deletion at any position, circular linked list variants, and real-world use cases like browser history.
Model dynamic programming as state machines — solve all Buy and Sell Stock variants (I-IV, cooldown, fee), understand state transitions, and build a general framework with Python.
Master string dynamic programming — Longest Common Subsequence, Edit Distance, Longest Palindromic Subsequence, Wildcard and Regex Matching with Python implementations and space optimization.
Master dynamic programming on trees — max independent set, tree diameter via DP, House Robber III, rerooting technique, and post-order traversal patterns with Python implementations.
Understand Euler paths, circuits, and Hamiltonian differences with Hierholzer's algorithm, degree conditions, and Python implementations.
Learn graph coloring with greedy coloring, bipartite check via 2-coloring, m-coloring with backtracking, and applications in scheduling.
Solve grid-based graph problems including flood fill, number of islands, shortest path in binary matrix, and surrounded regions with Python.
Learn how to detect cycles in directed and undirected graphs using DFS with parent tracking, three-color DFS, and Union-Find with Python implementations.
Master greedy algorithm patterns including activity selection, fractional knapsack, Huffman coding, job scheduling, and gas station. With proofs and Python code.
Learn when greedy algorithms work and when you need dynamic programming. Covers greedy choice property, optimal substructure, exchange arguments, and side-by-side comparisons.
Deep dive into hash map internals -- hash functions, collision resolution (chaining vs open addressing), load factor, rehashing, and building a hash map from scratch in Python.
Master advanced heap patterns -- merge K sorted lists, find median from data stream with two heaps, top K elements, task scheduler, and more with Python heapq implementations.
Understand heap sort, why build-heap is O(n) not O(n log n), sift-down vs sift-up, in-place sorting, partial sort for top K, and comparisons with other sorts.
Master interval problems — merge intervals, insert interval, meeting rooms, interval scheduling, sweep line technique, and non-overlapping intervals with Python implementations.
Find where two linked lists intersect using the two-pointer technique, length difference method, and hash set — with Python implementations and complexity analysis.
Learn Floyd's tortoise and hare algorithm for cycle detection in linked lists — detect cycles, find the start, measure cycle length, with full Python code and proofs.
Master every linked list reversal pattern — iterative, recursive, reverse in groups of K, and reverse between positions m and n, with Python code and common pitfalls.
Learn to merge two sorted lists, merge K sorted lists with a heap, and implement merge sort on linked lists with full Python code and complexity analysis.
Master LCA problems — recursive DFS for binary trees, BST property shortcut, parent pointers, and binary lifting for O(log n) queries. Full Python code.
Design and implement an LRU Cache from scratch using a HashMap and Doubly Linked List for O(1) get and put, with Python code, OrderedDict shortcut, and real-world context.
Master matrix traversal patterns — spiral order, diagonal traversal, zigzag, boundary traversal, matrix rotation, transpose, search in 2D matrix, and set matrix zeroes with Python.
Master merge sort — recursive splitting, merging sorted halves, counting inversions, merge sort on linked lists, stability analysis, and O(n log n) guaranteed performance with Python.
Understand max flow, residual graphs, augmenting paths, Ford-Fulkerson, Edmonds-Karp, and the max-flow min-cut theorem with Python code.
Master N-ary tree traversals and Trie data structure — autocomplete, spell check, word dictionary, wildcard search. Complete Python implementations.
Master multi-source BFS for rotting oranges, walls and gates, 01-BFS, and matrix distance problems with Python implementations.
Master queue variants — simple queue, deque, circular queue, and priority queue. Implementations in Python with BFS, sliding window, and scheduling examples.
Learn the Rabin-Karp algorithm for string matching using rolling hash. Covers polynomial hashing, collision avoidance, multiple pattern matching, and comparison with KMP.
Master quick sort — Lomuto and Hoare partitions, pivot strategies, worst case analysis, Dutch National Flag, QuickSelect for kth element, and comparison with merge sort.
Explore randomized algorithms -- QuickSelect for O(n) kth element, reservoir sampling for streams, randomized quicksort, skip lists, bloom filters, and Monte Carlo vs Las Vegas classification.
Learn to convert recursive algorithms to iterative ones. Covers tail recursion, explicit stacks, iterative tree traversals, Morris traversal, and memoization as a bridge to DP.