Skip to content
LUDA · 學思辨行

LUDA · 學思辨行

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

  • About
  • Learning Path

Category: Dynamic Programming

How weighted intervals choose by dynamic programming

November 13, 2026By HoHo Zhao

Short answer: Weighted interval scheduling picks a compatible set of intervals whose weights sum to the maximum. Sort by finishing time. For each interval j, let p(j) be the rightmost interval that finishes before j starts. Then the optimum for the first j intervals is the larger of weight(j)…

Algorithms, Dynamic ProgrammingLeave a comment

How unbounded knapsack reuses a capacity row

November 13, 2026By HoHo Zhao

Short answer: Unbounded knapsack, and the classic coin-change combination count, let each item be used any number of times. The same capacity array as 0-1 knapsack is scanned upward. When the loop reaches t, dp[t−w] already includes the choices just made for this item, so the item may be…

Algorithms, Dynamic ProgrammingLeave 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 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 matrix-chain order minimizes scalar multiplications

November 13, 2026By HoHo Zhao

Short answer: Matrix-chain multiplication chooses where to parenthesize a product of matrices so the number of scalar multiplications is minimized. Matrix i has dimensions p[i−1] by p[i]. The cost of multiplying a chain from i through j is the minimum, over the last multiplication’s split k, of the two…

Algorithms, Dynamic ProgrammingLeave a comment

How Kadane resets a running sum

November 13, 2026By HoHo Zhao

Short answer: Kadane’s algorithm finds the contiguous subarray of maximum sum in O(n) time and O(1) extra memory. It walks the array once, keeping the best sum that ends at the current index and the best sum seen anywhere. The sum that ends here is the current element plus…

Algorithms, Dynamic ProgrammingLeave a comment

How Held-Karp holds one subset per tour

November 13, 2026By HoHo Zhao

Short answer: The Held-Karp algorithm solves the traveling salesman problem on n cities by dynamic programming over subsets. The cell dp[S][v] is the minimum cost of a path that starts at city 0, visits each city in the subset S exactly once, and ends at v. Each cell tries…

Algorithms, Dynamic ProgrammingLeave a comment

How an optimal BST weights search cost

November 13, 2026By HoHo Zhao

Short answer: An optimal binary search tree puts keys in search-tree order and chooses the shape that minimizes the expected search cost. Key i is requested with probability p[i], and the gap between keys is requested with probability q[i]. The cost of a subtree is the sum of its…

Algorithms, Dynamic ProgrammingLeave a comment

How 0-1 knapsack fills a capacity row

November 13, 2026By HoHo Zhao

Short answer: The 0-1 knapsack problem takes each item at most once. With capacity W and n items, the cell dp[i][w] is the best value using the first i items and capacity w. The item is skipped, or it is taken when its weight fits, and the cell is…

Algorithms, Dynamic ProgrammingLeave a comment
  • 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.