Abstract Given a sequence of distinct positive integers , an increasing subsequence is a sequence such that and .

  • Category: Dynamic Programming / Sequence Problems
  • Input: A sequence of distinct positive integers
  • Output: The length (or an example) of the longest increasing subsequence
  • Paradigm: Reduction to Longest Path on a DAG (see Shortest Path in a DAG)
  • Typical use cases: patience sorting, version-control diffing, any “find the longest chain of compatible items” problem

Problem Specification

  • Instance: A sequence of distinct positive integers.
  • Solution Format: A subsequence with .
  • Constraints: (strictly increasing values), and indices strictly increasing.
  • Objective: , the length of the subsequence.
  • Goal: Maximize.

Example:

The longest increasing subsequence here is (length 5).


Viewing LIS as Shortest Path in a DAG

  • What could the vertices be? The values themselves — one vertex per element .
  • When is there an edge? An edge from if and (i.e. could immediately follow in an increasing subsequence).
  • What are the weights of edges? each.

Key Idea

Maximizing subsequence length is the same as maximizing the number of edges in a path through this DAG. Notable Properties turns “maximize number of edges” into “minimize total (negative) weight” — a plain shortest-path problem, solvable by the same topological-order DP, no priority queue needed.

Completing the Reduction

This setup isn’t quite single-source yet — an increasing subsequence can start at any element, not just a fixed one. The standard fix: add a virtual source vertex with a -weight edge to every . Then (in this -weighted graph) is for the longest increasing subsequence ending at , of length . The overall answer is .


Complexity

This DAG has vertices and up to edges (every pair with potentially contributes an edge). Running DAGDP on it costs — matching the classic direct-DP solution to Longest Increasing Subsequence (where , computed directly without explicitly building a graph).

Note

A better-known algorithm for LIS exists (using patience sorting / binary search over a list of smallest tail values per length), but it doesn’t fit the DAG-shortest-path framing directly — it’s a genuinely different technique, not a faster implementation of this reduction.


References / Links