Skip to content
LUDA · 學思辨行

LUDA · 學思辨行

Learn extensively, Understand deeply, Discern clearly, and Act resolutely.

  • About
  • Learning Path

Category: Algorithms

How the Z-algorithm boxes previous prefix matches

November 13, 2026By HoHo Zhao

Short answer: The Z-algorithm computes, for every index i of a string s, the length Z[i] of the longest substring starting at i that matches a prefix of s. It does this in O(n) time by reusing a window [left, right] that is the rightmost prefix match found so…

Algorithms, StringsLeave a comment

How the Viterbi algorithm decodes a hidden path

November 13, 2026By HoHo Zhao

Short answer: The Viterbi algorithm finds the most probable sequence of hidden states for a sequence of observations in a hidden Markov model. The cell v[t][s] is the probability of the best path that emits the first t observations and ends in state s. It multiplies the best predecessor…

Algorithms, Dynamic ProgrammingLeave a comment

How the simplex algorithm pivots a linear program

November 13, 2026By HoHo Zhao

Short answer: The simplex algorithm solves a linear program by walking from one vertex of the feasible polyhedron to a better neighbor. A basic feasible solution is a vertex. A pivot swaps one basic variable for one nonbasic variable and updates the tableau. If no neighbor improves the objective,…

Algorithms, OptimizationLeave a comment

How the sieve of Eratosthenes strikes composites

November 13, 2026By HoHo Zhao

Short answer: The sieve of Eratosthenes lists every prime up to n by striking multiples. For each prime p whose square is still at most n, it marks p·p, p·p+p, p·p+2p, and so on. Multiples below p² were already marked by smaller primes. The algorithm runs in O(n log…

Algorithms, Number TheoryLeave a comment

How the Lucas-Lehmer test checks a Mersenne number

November 13, 2026By HoHo Zhao

Short answer: The Lucas-Lehmer test decides whether a Mersenne number M = 2^p − 1 is prime, for an odd prime p. It sets s = 4 and repeats s = s² − 2, modulo M, p−2 times. M is prime exactly when the final s is 0 modulo…

Algorithms, Number TheoryLeave a comment

How the longest common subsequence fills a grid

November 13, 2026By HoHo Zhao

Short answer: The longest common subsequence of two strings is the longest sequence that appears in both, in order, not necessarily contiguously. The cell L[i][j] equals L[i−1][j−1] + 1 when the i-th and j-th characters match, and otherwise the maximum of L[i−1][j] and L[i][j−1]. The table is O(nm) time.…

Algorithms, StringsLeave a comment

How the linear sieve marks each composite once

November 13, 2026By HoHo Zhao

Short answer: The linear sieve computes the smallest prime factor of every integer up to n in O(n) arithmetic steps. It walks i from 2 to n, records i as prime when it has no factor yet, and for each known prime p marks p·i, stopping when p divides…

Algorithms, Number TheoryLeave a comment

How the Hungarian algorithm solves an assignment

November 13, 2026By HoHo Zhao

Short answer: The Hungarian algorithm, or Kuhn-Munkres, solves the assignment problem: pair n agents with n jobs so that the sum of costs is minimum. It maintains dual variables on agents and jobs so that a reduced cost c(i, j) − u(i) − v(j) is never negative, and it…

Algorithms, GraphsLeave a comment

How the Graham scan builds a convex hull

November 13, 2026By HoHo Zhao

Short answer: The Graham scan computes the convex hull of a finite set of points in the plane. It anchors the lowest point, sorts the rest by polar angle around that anchor, and walks the sorted list with a stack. A right turn, or a non-left turn, pops the…

Algorithms, GeometryLeave a comment

How the extended Euclidean algorithm writes Bezout

November 13, 2026By HoHo Zhao

Short answer: The extended Euclidean algorithm returns integers x and y such that a·x + b·y = gcd(a, b). It runs the same divisions as the Euclidean algorithm and also updates two coefficient rows, one for each remainder. The modular inverse of a modulo m exists exactly when the…

Algorithms, Number TheoryLeave a comment

How the Euclidean algorithm divides out a gcd

November 13, 2026By HoHo Zhao

Short answer: The Euclidean algorithm computes gcd(a, b) by replacing the pair with (b, a mod b) until the remainder is 0. The other number is the gcd. It runs in O(log min(a, b)) division steps, and the worst case is a pair of consecutive Fibonacci numbers, which makes…

Algorithms, Number TheoryLeave a comment

How the egg dropping recurrence limits the worst case

November 13, 2026By HoHo Zhao

Short answer: The egg dropping problem asks for the minimum number of trials that suffice, in the worst case, to find a critical floor with e eggs and f floors. Dropping at floor x leaves either e−1 eggs and x−1 floors below, if the egg breaks, or e eggs…

Algorithms, Dynamic ProgrammingLeave a comment

How the CYK algorithm parses a Chomsky grammar

November 13, 2026By HoHo Zhao

Short answer: The CYK algorithm decides whether a string belongs to a context-free grammar in Chomsky normal form, and it builds a parse table while doing so. Cell (length, start, variable) is true when that variable derives the substring. A production A → B C splits the substring into…

Algorithms, Dynamic ProgrammingLeave a comment

How the closest pair of points searches a strip

November 13, 2026By HoHo Zhao

Short answer: The closest pair algorithm finds the minimum Euclidean distance in a planar set by divide and conquer. It sorts by x, splits the set in half, solves both halves, and then checks only the points that lie in a strip of width δ around the cut, where…

Algorithms, GeometryLeave a comment

How the clock algorithm approximates LRU

November 13, 2026By HoHo Zhao

Short answer: The clock algorithm, or second chance, approximates LRU with a circular list of frames and one reference bit each. The clock hand walks the circle. A frame whose bit is 1 gets the bit cleared and a second chance. A frame whose bit is 0 is evicted.…

Algorithms, SystemsLeave a comment

How the Chinese remainder theorem builds a residue

November 13, 2026By HoHo Zhao

Short answer: The Chinese remainder theorem says that if the moduli m1, …, mk are pairwise coprime, then for any residues a1, …, ak there is one solution modulo M = m1·…·mk of the system x ≡ ai (mod mi). The constructive form computes, for each i, the product…

Algorithms, Number TheoryLeave a comment

How the Burrows-Wheeler transform sorts rotations

November 13, 2026By HoHo Zhao

Short answer: The Burrows-Wheeler transform sorts every rotation of a string and emits the last character of each rotation, plus the index of the original string in that sorted list. The output is a permutation that tends to group identical characters, which is why it sits in front of…

Algorithms, StringsLeave a comment

How the Boyer-Moore vote finds a majority candidate

November 13, 2026By HoHo Zhao

Short answer: The Boyer-Moore majority vote finds a candidate that is the only value that could be a strict majority of an array, using one counter and one candidate. It scans once. On a match it increments. On a mismatch it decrements. At zero it takes the current value…

Algorithms, SequencesLeave a comment

Posts pagination

Previous 1 2 3 4 5 … 12 Next
  • Algorithms
  • Arithmetic
  • Authelia
  • Clustering
  • Coding
  • Compression
  • Cryptography
  • CSS
  • Distributed Systems
  • Docker
  • Dynamic Programming
  • Exact Algorithms
  • Games
  • Geometry
  • Grafana
  • Graphs
  • Greedy
  • Heaps
  • Homelab
  • IPsec
  • LDAP
  • Linear Algebra
  • Logging
  • Loki
  • nginx
  • Number Theory
  • Numerical
  • Optimization
  • Parsing
  • Prometheus
  • Randomization
  • Range Queries
  • Sampling
  • Scheduling
  • Search
  • Searching
  • Sequences
  • Sketches
  • Sorting
  • Streams
  • Strings
  • SVG
  • Synchronization
  • Systems
  • Transforms
  • Trees

Docker EAP-MSCHAPv2 FreeRADIUS Grafana gzip IKEv2 IPsec LogQL Loki OpenLDAP Promtail StrongSwan

© 2026 LUDA · 學思辨行. Powered by WordPress.