Longest Increasing Subsequence Visualizer

Paste a numeric array, compare each index with prior values, and backtrack one longest increasing subsequence.

Values
8
LIS length
4
Index i
0
Compare j
-

Array input

Step controls

Start with LIS length 1 at each of 8 indexes.

Sequence state

0
1
2
3
4
5
6
7
10 dp=1
9 dp=1
2 dp=1
5 dp=1
3 dp=1
7 dp=1
101 dp=1
18 dp=1

LIS output

operation = Start
i = 0
j = -
candidate = -
lis_length = 4
sequence = [2, 5, 7, 101]

Length table

IndexValuedpprev
0101-1
191-1
221-1
351-1
431-1
571-1
61011-1
7181-1
1: 22: 53: 74: 101

What is a Longest Increasing Subsequence Visualizer?

A longest increasing subsequence visualizer shows the longest ordered subset of values where every next value is larger than the previous value. The values do not need to be adjacent in the original array.

This tool uses the O(n^2) dynamic programming approach so you can see every prior-index comparison, each length update, and the final backtracked subsequence.

For the full algorithm set, browse the Data Structure Visualizers hub.

How to use this LIS visualizer

  • Enter an array of numbers.
  • Click Run LIS to compute the longest increasing subsequence.
  • Step forward to compare the current value against earlier values.
  • Inspect the best length ending at each index.
  • Read the final sequence in the output panel.

LIS and dynamic programming

For each index i, the DP value stores the best increasing subsequence that ends at i. If a previous value is smaller, it can extend that previous subsequence by one.

For related dynamic programming tools, try the Fibonacci DP Visualizer, Coin Change DP Visualizer, Longest Common Subsequence Visualizer, and Knapsack DP Visualizer.

Frequently Asked Questions

What does subsequence mean in LIS?
A subsequence keeps the original order but can skip values. The selected values do not need to be adjacent.
Does the sequence have to be strictly increasing?
Yes. This visualizer uses the strict rule `previous value < current value`.
What does dp[i] store?
dp[i] stores the length of the best increasing subsequence that ends exactly at index i.
What is the time complexity of this LIS visualizer?
This visualizer uses the O(n^2) DP algorithm because it makes each comparison easy to inspect.

Related tools