SMAWK & Monge Matrices — All Row Minima in O(n + m)

A totally monotone matrix has a non-decreasing staircase of row minima. SMAWK finds them all via REDUCE (drop dead columns) + INTERPOLATE (recurse even rows, fill odd).

idle

Totally Monotone Matrix — rows = i, columns = j

row minimum (staircase) even rows (recurse) odd-row scan window eliminated column current scan cell

What just happened

Press Step ▶ or Run ⏩ to watch SMAWK find every row minimum.

Stats

Phase
Matrix size n×m
Cells touched (SMAWK)0
Naive scan would touch0
Rows resolved0

Complexity

MethodTime
Brute force (all cells)O(n·m)
Divide & conquer (sib. 12)O((n+m) log n)
SMAWK (this)O(n + m)
One DP layer (SMAWK)O(n)
K-layer DP (SMAWK)O(K·n)

Precondition: matrix is totally monotone (Monge ⟹ TM). Otherwise the answer is silently wrong.

Operation Log