cswork / libraryOpen practice workspace

READ. UNDERSTAND. PRACTICE.

Algorithm tutorials

Explore algorithm tutorials, coding and system design questions, interview experiences, and computer science study guides.

100 resources · Page 1 of 5

  1. Algorithm tutorials

    A*, Iterative Deepening and IDA* Search

    Heuristic shortest-path search: A* with admissible and consistent heuristics, iterative deepening DFS and IDA* for memory-light searches, and the sliding-puzzle case study including the inversion-parity solvability test.

  2. Algorithm tutorials

    Aho-Corasick Automaton (Multi-Pattern Matching)

    A trie of all patterns plus KMP-style failure links lets one left-to-right pass over the text report every occurrence of every pattern, count occurrences per pattern, or answer streaming queries.

  3. Algorithm tutorials

    Backtracking and DFS Search with Pruning

    Exhaustive search by recursion: the choose-explore-unchoose template for subsets, permutations, partitions, N-Queens and grid paths, how to avoid duplicate answers, and pruning (feasibility, bounds, ordering, memoization) that makes it fast enough.

  4. Algorithm tutorials

    BFS for Minimum Steps: Grids and State Spaces

    Breadth-first search as the go-to tool for 'fewest moves' questions: grid BFS, implicit state graphs, multi-source BFS, BFS over augmented states, and 0-1 BFS with a deque for 0/1 edge costs.

  5. Algorithm tutorials

    Bidirectional BFS and Meet in the Middle

    Halve the exponent of a search: bidirectional BFS that grows the smaller frontier from both ends, and meet in the middle that enumerates two halves of a subset problem separately and combines them with sorting, binary search or hashing.

  6. Algorithm tutorials

    Big Integer Arithmetic on Strings

    Schoolbook arithmetic for numbers stored as digit strings: addition in any base up to 10, comparison, subtraction with borrows, multiplication with position i+j accumulation, long division by a small integer, and computing a huge number modulo m digit by digit.

  7. Algorithm tutorials

    Binary Lifting (Jump Pointers)

    Precompute where you land after 1, 2, 4, 8, ... steps so that any k-step jump takes O(log k): k-th ancestor queries, lowest common ancestor, huge jump counts on functional graphs, and the sparse table built on the same doubling idea.

  8. Algorithm tutorials

    Binary Search, Binary Search on the Answer, and Ternary Search

    One invariant-based template for every binary search: lower and upper bounds, rotated arrays, peaks, binary search on the answer for min-max and max-min problems, real-valued search, and ternary search on unimodal functions.

  9. Algorithm tutorials

    Binary Search Tree

    BST search, insert, delete, validation, k-th smallest and floor/ceiling in O(h), plus what balanced trees (AVL, red-black) guarantee and which ordered-map library to use in Java, C++ and Python.

  10. Algorithm tutorials

    Bipartite Graphs and Two-Coloring

    A graph is bipartite exactly when it can be two-colored, which happens exactly when it has no odd cycle. Check it with BFS coloring, or with a parity union-find when edges arrive one by one.

  11. Algorithm tutorials

    Bipartite Matching (Augmenting Paths)

    Kuhn's augmenting-path algorithm for maximum bipartite matching in O(V * E), plus the theorems that turn matching into answers for minimum vertex cover, maximum independent set and minimum path cover in a DAG.

  12. Algorithm tutorials

    Bit Manipulation: Tricks, XOR and Bitmasks

    The bit tricks interviews keep asking for: two's complement, lowbit and clearing the lowest set bit, popcount, XOR cancellation for unpaired elements, bitmasks as sets with subset and submask enumeration, Gosper's hack, and 32-bit arithmetic in Python.

  13. Algorithm tutorials

    Bitmask DP: Subsets, Assignments and Row Profiles

    Dynamic programming over subsets encoded as bitmasks for small n: subset-plus-last-node states (Hamiltonian paths, TSP), assignment DP, partitioning with submask enumeration in O(3^n), and row-by-row profile DP on narrow grids.

  14. Algorithm tutorials

    Bridges, Articulation Points and Biconnected Components

    Find every edge (bridge) and vertex (articulation point) whose removal disconnects an undirected graph in one O(n + m) DFS using discovery times and low-links, then group vertices into 2-edge-connected components.

  15. Algorithm tutorials

    Brute Force and Enumeration

    How to write a correct brute-force solution and then shrink the search space: symmetry, fixing one variable and looking up the rest, enumerating subsets, and enumerating a small part to force the rest.

  16. Algorithm tutorials

    Catalan Numbers

    Recognize and compute Catalan numbers: the split-into-two recurrence behind binary tree shapes, balanced parentheses and non-crossing handshakes, the closed form via the reflection principle, ballot counts, modular computation and generating all structures by backtracking.

  17. Algorithm tutorials

    Combinatorics Basics: nCk, Stars and Bars, Pigeonhole

    The counting toolkit for interviews: sum and product rules, permutations and combinations, computing nCk exactly, with Pascal's triangle or with factorial tables modulo a prime, stars and bars, multiset arrangements, and the pigeonhole principle turned into algorithms.

  18. Algorithm tutorials

    Time and Space Complexity Analysis

    How to derive and state Big-O time and space costs in interviews: loop and recursion analysis, the master theorem, amortized analysis, and practical ways to cut memory.

  19. Algorithm tutorials

    Coordinate Compression (Discretization)

    Replace huge or sparse values by their ranks so they can index arrays, Fenwick trees and difference arrays, while keeping the real gap lengths when the problem needs them.

  20. Algorithm tutorials

    Counting Sort, Bucket Sort and Radix Sort

    Linear-time sorting by looking at values instead of comparing them: stable counting sort with prefix sums, bucketing by value or frequency (top-k frequent, maximum gap), and LSD radix sort.

  21. Algorithm tutorials

    Counting DP: Counting Every Object Exactly Once

    How to count ways with dynamic programming without double counting: classify objects by a single decisive feature such as the last step, handle ordered versus unordered sums, and apply the pattern to decodings, grid paths, partitions and dice sums modulo 10^9+7.

  22. Algorithm tutorials

    Digit DP

    Count integers up to 10^18 whose digits satisfy a rule by building them digit by digit with tight and leading-zero flags, memoizing on the position and a small summary of the prefix, and answering ranges with prefix differences.

  23. Algorithm tutorials

    DP Optimization: Sliding Window Sums, Monotonic Deques and Fenwick Trees

    Remove the inner loop of a DP whose transition aggregates over a window or over smaller values: sliding window sums for probabilities and counts, monotonic deques for window max/min (including bounded knapsack in O(nW)), and Fenwick trees over value ranks.

  24. Algorithm tutorials

    DP State Design: State Machines and Swapped Dimensions

    How to pick a DP state that carries exactly what the future needs: add a small mode dimension (the stock-trading state machines with fees, cooldowns and k transactions) or swap the answer with a huge dimension (refueling stops, knapsack indexed by value).