DSA Explorer
QuicksortMerge SortBubble SortInsertion SortSelection SortHeap SortCounting SortRadix SortBucket SortShell SortTim SortCocktail Shaker SortComb SortGnome SortPancake SortPatience SortCycle SortStrand SortWiggle Sort (Wave Sort)Bead Sort (Gravity Sort)Binary Insertion SortBitonic SortBogo Sort (Stupid Sort)Stooge SortOdd-Even Sort (Brick Sort)Pigeonhole SortIntro Sort (Introspective Sort)Tree Sort (BST Sort)Dutch National Flag (3-Way Partitioning)
Binary SearchLinear SearchJump SearchInterpolation SearchExponential SearchTernary SearchFibonacci SearchQuick Select (k-th Smallest)Median of Medians (Deterministic Select)Hill climbingSimulated AnnealingTabu SearchBinary Tree DFS SearchSentinel Linear SearchDouble Linear SearchTernary Search (Unimodal Function)Search in 2D Matrix
Binary Search Tree (BST)StackQueueHash Table (Hash Map)Heap (Priority Queue)Linked ListTrie (Prefix Tree)Binary TreeTrie (Prefix Tree)Floyd's Cycle Detection (Tortoise and Hare)Merge Two Sorted Linked ListsCheck if Linked List is PalindromeFind Middle of Linked ListBalanced Parentheses (Valid Parentheses)Next Greater ElementInfix to Postfix ConversionMin Stack (O(1) getMin)Largest Rectangle in HistogramDaily Temperatures (Monotonic Stack)Evaluate Reverse Polish NotationInfix Expression Evaluation (Two Stacks)Min Heap & Max HeapSliding Window MaximumTrapping Rain WaterRotate Matrix 90 DegreesSpiral Matrix TraversalSet Matrix ZeroesHash Table with ChainingOpen Addressing (Linear Probing)Double HashingCuckoo Hashing
Depth-First Search (DFS)Breadth-First Search (BFS)Dijkstra's AlgorithmFloyd-Warshall AlgorithmKruskal's AlgorithmPrim's AlgorithmTopological SortA* Pathfinding AlgorithmKahn's Algorithm (Topological Sort)Ford-Fulkerson Max FlowEulerian Path/CircuitBipartite Graph CheckBorůvka's Algorithm (MST)Bidirectional DijkstraPageRank AlgorithmBellman-Ford AlgorithmTarjan's Strongly Connected ComponentsArticulation Points (Cut Vertices)Find Bridges (Cut Edges)Articulation Points (Cut Vertices)Finding Bridges (Cut Edges)
0/1 Knapsack ProblemLongest Common Subsequence (LCS)Edit Distance (Levenshtein Distance)Longest Increasing Subsequence (LIS)Coin Change ProblemFibonacci Sequence (DP)Matrix Chain MultiplicationRod Cutting ProblemPalindrome Partitioning (Min Cuts)Subset Sum ProblemWord Break ProblemLongest Palindromic SubsequenceMaximal Square in MatrixInterleaving StringEgg Drop ProblemUnique Paths in GridCoin Change II (Count Ways)Decode WaysWildcard Pattern MatchingRegular Expression MatchingDistinct SubsequencesMaximum Product SubarrayHouse RobberClimbing StairsPartition Equal Subset SumKadane's Algorithm (Maximum Subarray)
A* Search AlgorithmConvex Hull (Graham Scan)Line Segment IntersectionCaesar CipherVigenère CipherRSA EncryptionHuffman CompressionRun-Length Encoding (RLE)Lempel-Ziv-Welch (LZW)Canny Edge DetectionGaussian Blur FilterSobel Edge FilterHarris Corner DetectionHistogram EqualizationMedian FilterLaplacian FilterMorphological ErosionMorphological DilationImage Thresholding (Otsu's Method)Conway's Game of LifeLangton's AntRule 30 Cellular AutomatonFast Fourier Transform (FFT)Butterworth FilterSpectrogram (STFT)
Knuth-Morris-Pratt (KMP) AlgorithmRabin-Karp AlgorithmBoyer-Moore AlgorithmAho-Corasick AlgorithmManacher's AlgorithmSuffix ArraySuffix Tree (Ukkonen's Algorithm)Trie for String MatchingEdit Distance for StringsLCS for String MatchingHamming DistanceJaro-Winkler DistanceDamerau-Levenshtein DistanceBitap Algorithm (Shift-Or, Baeza-Yates-Gonnet)Rolling Hash (Rabin-Karp Hash)Manacher's AlgorithmZ AlgorithmLevenshtein Distance

Longest Increasing Subsequence (LIS)

Dynamic Programming
O(n²) or O(n log n) time, O(n) space
Intermediate

Longest Increasing Subsequence (LIS) finds the length of the longest subsequence in an array where all elements are in strictly increasing order. Unlike a subarray, a subsequence doesn't need to be contiguous - elements can be selected from anywhere as long as their order is preserved. This classic DP problem has two solutions: O(n²) dynamic programming and O(n log n) binary search with patience sorting. Applications include stock price analysis, scheduling, Box Stacking Problem, and Building Bridges Problem.

Prerequisites:
Dynamic Programming
Binary Search
Arrays

Visualization

Interactive visualization for Longest Increasing Subsequence (LIS)

Longest Increasing Subsequence (LIS)

Array:

[0]
10
[1]
9
[2]
2
[3]
5
[4]
3
[5]
7
[6]
101
[7]
18

• Time: O(n²) - DP approach

• Space: O(n)

• O(n log n) possible with binary search

Interactive visualization with step-by-step execution

Implementation

Language:
1// O(n²) DP solution
2function lisDP(arr: number[]): number {
3  const n = arr.length;
4  const dp: number[] = Array(n).fill(1);
5  
6  for (let i = 1; i < n; i++) {
7    for (let j = 0; j < i; j++) {
8      if (arr[j] < arr[i]) {
9        dp[i] = Math.max(dp[i], dp[j] + 1);
10      }
11    }
12  }
13  
14  return Math.max(...dp);
15}
16
17// O(n log n) Binary Search solution
18function lisBinarySearch(arr: number[]): number {
19  const tails: number[] = [];
20  
21  for (const num of arr) {
22    let left = 0;
23    let right = tails.length;
24    
25    while (left < right) {
26      const mid = Math.floor((left + right) / 2);
27      if (tails[mid] < num) {
28        left = mid + 1;
29      } else {
30        right = mid;
31      }
32    }
33    
34    if (left === tails.length) {
35      tails.push(num);
36    } else {
37      tails[left] = num;
38    }
39  }
40  
41  return tails.length;
42}

Deep Dive

Theoretical Foundation

LIS demonstrates optimal substructure: if we know LIS ending at position i, we can extend it by appending arr[j] where j > i and arr[j] > arr[i]. **O(n²) DP**: dp[i] = length of LIS ending at i. For each i, check all j < i: if arr[j] < arr[i], dp[i] = max(dp[i], dp[j]+1). Answer is max(dp). **O(n log n)**: Maintain array 'tails' where tails[i] = smallest tail element of all increasing subsequences of length i+1. For each number, binary search its position in tails (first element >= number) and replace. This greedy approach works because smaller tails give more room for future extensions. Tails length = LIS length. This technique is called 'patience sorting' and is used in real solitaire games!

Complexity

Time

Best

O(n log n)

Average

O(n²) or O(n log n)

Worst

O(n²)

Space

Required

O(n)

Applications

Industry Use

1

Stock price analysis (longest profit-making sequence)

2

Patience sorting card game strategy

3

Box stacking problem (3D version)

4

Building bridges without crossing

5

Scheduling tasks with dependencies

6

Version control (longest consistent chain)

7

Bioinformatics sequence analysis

Use Cases

Stock market analysis
Scheduling
Patience sorting

Related Algorithms

0/1 Knapsack Problem

A classic optimization problem where you must select items with given weights and values to maximize total value without exceeding the knapsack's capacity. Each item can be taken only once (0 or 1). This is a fundamental problem in combinatorial optimization, resource allocation, and decision-making scenarios.

Dynamic Programming

Longest Common Subsequence (LCS)

Finds the longest subsequence common to two sequences. A subsequence is a sequence that appears in the same relative order but not necessarily contiguously. This is fundamental in diff utilities, DNA sequence analysis, and version control systems like Git.

Dynamic Programming

Edit Distance (Levenshtein Distance)

Edit Distance, also known as Levenshtein Distance, computes the minimum number of single-character edits (insertions, deletions, or substitutions) required to transform one string into another. Named after Soviet mathematician Vladimir Levenshtein who introduced it in 1965, this fundamental algorithm has applications in spell checking, DNA sequence analysis, natural language processing, and plagiarism detection.

Dynamic Programming

Coin Change Problem

The Coin Change Problem finds the minimum number of coins needed to make a given amount using unlimited supplies of given coin denominations. It's a classic example of both dynamic programming and greedy algorithms, with two main variants: finding the minimum number of coins (optimization) and counting the number of ways to make change (counting). This problem has direct applications in currency systems, vending machines, and resource optimization.

Dynamic Programming
DSA Explorer

Master Data Structures and Algorithms through interactive visualizations and detailed explanations. Our platform helps you understand complex concepts with clear examples and real-world applications.

Quick Links

  • About DSA Explorer
  • All Algorithms
  • Data Structures
  • Contact Support

Legal

  • Privacy Policy
  • Terms of Service
  • Cookie Policy
  • Code of Conduct

Stay Updated

Subscribe to our newsletter for the latest algorithm explanations, coding challenges, and platform updates.

We respect your privacy. Unsubscribe at any time.

© 2026 Momin Studio. All rights reserved.

SitemapAccessibility
v1.0.0