SlideShare a Scribd company logo
2
Most read
3
Most read
21
Most read
LONGEST INCREASING SUBSEQUENCE
Algorithm Design Course
TA Sessions
By S. Daneshvar
Longest increasing subsequence
Find the length of the longest subsequence of a given array such that all elements of
the array are sorted in an increasing order.
For instance:
Input: {10, 22, 9, 33, 21, 50, 41, 60}
Subsequences: {10}, {22}, … , {10, 9, 33} ,{33, 21 , 50, 60}, etc.
Increasing Subsequence: {10}, {22}, … , {33, 50, 60} , … ,{ 10, 22, 33, 50 , 60} ,etc.
Longest Increasing Subsequence: {10,22,33,50,60} => Length(LIS) = 5
Longest increasing subsequence
Brute Force vs Dynamic Programming?
Longest increasing subsequence
Dynamic Programming Approach:
Iterator
Array 10 22 9 33 21 50 41 60
LIS 1 1 1 1 1 1 1 1
Longest increasing subsequence
Dynamic Programming Approach:
For i = 1:
Iterator j i
Array 10 22 9 33 21 50 41 60
LIS 1 1 1 1 1 1 1 1
Longest increasing subsequence
Dynamic Programming Approach:
For i = 1:
Iterator j i
Array 10 22 9 33 21 50 41 60
LIS 1 2 1 1 1 1 1 1
Longest increasing subsequence
Dynamic Programming Approach:
For i = 2:
Iterator j i
Array 10 22 9 33 21 50 41 60
LIS 1 2 1 1 1 1 1 1
Longest increasing subsequence
Dynamic Programming Approach:
For i = 3:
Iterator j i
Array 10 22 9 33 21 50 41 60
LIS 1 2 1 1 1 1 1 1
Longest increasing subsequence
Dynamic Programming Approach:
For i = 3:
Iterator j i
Array 10 22 9 33 21 50 41 60
LIS 1 2 1 2 1 1 1 1
Longest increasing subsequence
Dynamic Programming Approach:
For i = 3:
Iterator j i
Array 10 22 9 33 21 50 41 60
LIS 1 2 1 3 1 1 1 1
Longest increasing subsequence
Dynamic Programming Approach:
For i = 4:
Iterator j i
Array 10 22 9 33 21 50 41 60
LIS 1 2 1 3 1 1 1 1
Longest increasing subsequence
Dynamic Programming Approach:
For i = 4:
Iterator j i
Array 10 22 9 33 21 50 41 60
LIS 1 2 1 3 2 1 1 1
Longest increasing subsequence
Dynamic Programming Approach:
For i = 4:
Iterator j i
Array 10 22 9 33 21 50 41 60
LIS 1 2 1 3 2 1 1 1
Longest increasing subsequence
Dynamic Programming Approach:
For i = 4:
Iterator j i
Array 10 22 9 33 21 50 41 60
LIS 1 2 1 3 2 1 1 1
Longest increasing subsequence
Dynamic Programming Approach:
For i = 5:
Iterator j i
Array 10 22 9 33 21 50 41 60
LIS 1 2 1 3 2 1 1 1
Longest increasing subsequence
Dynamic Programming Approach:
For i = 5:
Iterator j i
Array 10 22 9 33 21 50 41 60
LIS 1 2 1 3 2 2 1 1
Longest increasing subsequence
Dynamic Programming Approach:
For i = 5:
Iterator j i
Array 10 22 9 33 21 50 41 60
LIS 1 2 1 3 2 3 1 1
Longest increasing subsequence
Dynamic Programming Approach:
For i = 5:
Iterator j i
Array 10 22 9 33 21 50 41 60
LIS 1 2 1 3 2 3 1 1
Longest increasing subsequence
Dynamic Programming Approach:
For i = 5:
Iterator j i
Array 10 22 9 33 21 50 41 60
LIS 1 2 1 3 2 4 1 1
Longest increasing subsequence
Dynamic Programming Approach:
Final Result:
Iterator j i
Array 10 22 9 33 21 50 41 60
LIS 1 2 1 3 2 4 4 5
Longest increasing subsequence
Integer LongestIncreasingSubsequence( Integer[] array ) {
Integer[] lis = new Integer[array.length];
for ( int i = 0 ; i < array.length ; i++)
lis[i] = 1;
for ( int i = 0 ; i < array.length ; i++)
for ( int j = 0; j < i ; j++)
if( array[j] < array [i] && lis[i] < lis[j] + 1)
lis[i] = lis[j] + 1
return max( lis ) // O(n)
}

More Related Content

PPTX
The n Queen Problem
PPT
Medians and order statistics
PPT
Greedy Algorihm
PPT
PPTX
Code Optimization
PPTX
Dijkstra's algorithm presentation
PPTX
Linear search-and-binary-search
PPTX
Tsp branch and-bound
The n Queen Problem
Medians and order statistics
Greedy Algorihm
Code Optimization
Dijkstra's algorithm presentation
Linear search-and-binary-search
Tsp branch and-bound

What's hot (20)

PDF
Bellman-Ford-Moore Algorithm and Dijkstra’s Algorithm
PPTX
Merge sort algorithm
PPT
decoder and encoder
PPTX
sum of subset problem using Backtracking
PPTX
Xilinx 4000 series
PDF
Lexical Analysis - Compiler design
PPT
Code Optimization
PPT
Syntax and semantics of propositional logic
PPTX
All pair shortest path
PDF
Bellman ford algorithm
PDF
Syntax directed translation
PDF
All pairs shortest path algorithm
PDF
Issues in the design of Code Generator
PPTX
implementation of travelling salesman problem with complexity ppt
PDF
linear search and binary search
PPT
Clock gating
PPT
Sum of subsets problem by backtracking 
PDF
COMPILER DESIGN- Syntax Directed Translation
PPTX
Travelling salesman dynamic programming
PPTX
Dynamic Programming
Bellman-Ford-Moore Algorithm and Dijkstra’s Algorithm
Merge sort algorithm
decoder and encoder
sum of subset problem using Backtracking
Xilinx 4000 series
Lexical Analysis - Compiler design
Code Optimization
Syntax and semantics of propositional logic
All pair shortest path
Bellman ford algorithm
Syntax directed translation
All pairs shortest path algorithm
Issues in the design of Code Generator
implementation of travelling salesman problem with complexity ppt
linear search and binary search
Clock gating
Sum of subsets problem by backtracking 
COMPILER DESIGN- Syntax Directed Translation
Travelling salesman dynamic programming
Dynamic Programming
Ad

Similar to Longest increasing subsequence (20)

PPTX
TSIndexingIndexacao De Série ttemporal.pptx
PDF
RNN and sequence-to-sequence processing
PPTX
Hybrid Machine Translation by Combining Multiple Machine Translation Systems
PDF
digital signal-processing-lab-manual
DOCX
Divide-and-Conquer & Dynamic ProgrammingDivide-and-Conqu.docx
PDF
Lecture_DynamicProgramming test12345.pdf
PPT
Lecture#9
PPTX
Ch-2 final exam documet compler design elements
PPTX
Dynamic Programming - Part II
PDF
008. PROGRAM EFFICIENCY computer science.pdf
PPTX
Algorithm for the DAA agscsnak javausmagagah
PDF
Time and Space Complexity
PPT
Lecture 1 and 2 of Data Structures & Algorithms
DOCX
DSP_Lab_MAnual_-_Final_Edition[1].docx
PDF
Dynamic programing
PDF
DSP_Lab_MAnual_-_Final_Edition.pdf
PPTX
ODU ACM Python & Memento Presentation
PDF
EC8553 Discrete time signal processing
PDF
Practical and Worst-Case Efficient Apportionment
PPTX
dynamic programming complete by Mumtaz Ali (03154103173)
TSIndexingIndexacao De Série ttemporal.pptx
RNN and sequence-to-sequence processing
Hybrid Machine Translation by Combining Multiple Machine Translation Systems
digital signal-processing-lab-manual
Divide-and-Conquer & Dynamic ProgrammingDivide-and-Conqu.docx
Lecture_DynamicProgramming test12345.pdf
Lecture#9
Ch-2 final exam documet compler design elements
Dynamic Programming - Part II
008. PROGRAM EFFICIENCY computer science.pdf
Algorithm for the DAA agscsnak javausmagagah
Time and Space Complexity
Lecture 1 and 2 of Data Structures & Algorithms
DSP_Lab_MAnual_-_Final_Edition[1].docx
Dynamic programing
DSP_Lab_MAnual_-_Final_Edition.pdf
ODU ACM Python & Memento Presentation
EC8553 Discrete time signal processing
Practical and Worst-Case Efficient Apportionment
dynamic programming complete by Mumtaz Ali (03154103173)
Ad

More from S.Shayan Daneshvar (8)

PPTX
Image to image translation with Pix2Pix GAN
PDF
Microservice architecture (MSA) and patterns
PDF
PostgreSQL - Case Study
PDF
Advanced SQL - Database Access from Programming Languages
PPTX
P, NP and NP-Complete, Theory of NP-Completeness V2
PPTX
Analysis of algorithms
PPTX
Amortized analysis
PPTX
Introduction to MongoDB
Image to image translation with Pix2Pix GAN
Microservice architecture (MSA) and patterns
PostgreSQL - Case Study
Advanced SQL - Database Access from Programming Languages
P, NP and NP-Complete, Theory of NP-Completeness V2
Analysis of algorithms
Amortized analysis
Introduction to MongoDB

Recently uploaded (20)

PDF
AI in Product Development-omnex systems
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PPTX
Introduction to Artificial Intelligence
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PPTX
Odoo POS Development Services by CandidRoot Solutions
PDF
Digital Strategies for Manufacturing Companies
PDF
top salesforce developer skills in 2025.pdf
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PPTX
Operating system designcfffgfgggggggvggggggggg
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PPTX
history of c programming in notes for students .pptx
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PDF
Understanding Forklifts - TECH EHS Solution
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PDF
System and Network Administration Chapter 2
PPTX
Essential Infomation Tech presentation.pptx
AI in Product Development-omnex systems
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
Introduction to Artificial Intelligence
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
Design an Analysis of Algorithms II-SECS-1021-03
Odoo POS Development Services by CandidRoot Solutions
Digital Strategies for Manufacturing Companies
top salesforce developer skills in 2025.pdf
Which alternative to Crystal Reports is best for small or large businesses.pdf
Operating system designcfffgfgggggggvggggggggg
Navsoft: AI-Powered Business Solutions & Custom Software Development
history of c programming in notes for students .pptx
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
wealthsignaloriginal-com-DS-text-... (1).pdf
Understanding Forklifts - TECH EHS Solution
VVF-Customer-Presentation2025-Ver1.9.pptx
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
Adobe Illustrator 28.6 Crack My Vision of Vector Design
System and Network Administration Chapter 2
Essential Infomation Tech presentation.pptx

Longest increasing subsequence

Editor's Notes

  • #2: Are your classroom colors different than what you see in this template? That’s OK! Click on Design -> Variants (the down arrow) -> Pick the color scheme that works for you! Feel free to change any “You will…” and “I will…” statements to ensure they align with your classroom procedures and rules!