SlideShare a Scribd company logo
1 of 55
Download to read offline
POSCAT Seminar 7 :
Dynamic Programming 1
yougatup @ POSCAT
1
Topic
 Topic today
− Dynamic Programming
• Basic Concept
• Longest Increasing Subsequence
• Longest Common Subsequence
POSCAT Seminar 1-2
9 July 2014
yougatup
Dynamic Programming
 Problem Solving Paradigm
− Identifying a collection of subproblems
− Tackling them one by one
• smallest first
• using the answer already calculated to help figure out the
larger ones
• until the whole problem is solved
 One of the most prominent issue
− You can be familiar with PS with Dynamic Programming
− There are so many issues to cover
POSCAT Seminar 1-3
9 July 2014
yougatup
Dynamic Programming
 Procedure
1. Define the Table
2. Find recurrence relation
3. Calculate !
POSCAT Seminar 1-4
9 July 2014
yougatup
Longest Increasing Subsequence
 Problem
Find an increasing subsequence of greatest length
5 2 8 6 3 6 9 7
POSCAT Seminar 1-5
9 July 2014
yougatup
Longest Increasing Subsequence
 Problem
Find an increasing subsequence of greatest length
5 2 8 6 3 6 9 7
POSCAT Seminar 1-6
9 July 2014
yougatup
Longest Increasing Subsequence
 Problem
Find an increasing subsequence of greatest length
5 2 8 6 3 6 9 7
1. Define the Table
POSCAT Seminar 1-7
9 July 2014
yougatup
Longest Increasing Subsequence
 Problem
Find an increasing subsequence of greatest length
5 2 8 6 3 6 9 7
1. Define the Table
Let 𝑇(𝑖) = The length of LIS when 𝑎𝑖 is the last element
∴ 𝑎𝑖 have to be last element of subsequence
POSCAT Seminar 1-8
9 July 2014
yougatup
Longest Increasing Subsequence
 Problem
Find an increasing subsequence of greatest length
5 2 8 6 3 6 9 7
1. Define the Table
You can fill the table manually. What is the answer ?
POSCAT Seminar 1-9
9 July 2014
yougatup
index 0 1 2 3 4 5 6 7
Data 5 2 8 6 3 6 9 7
Table 1 1 2 2 2 3 4 4
Longest Increasing Subsequence
 Problem
Find an increasing subsequence of greatest length
5 2 8 6 3 6 9 7
1. Define the Table
Can you see the recurrence relation on 𝑇 ?
POSCAT Seminar 1-10
9 July 2014
yougatup
index 0 1 2 3 4 5 6 7
Data 5 2 8 6 3 6 9 7
Table 1 1 2 2 2 3 4 4
Longest Increasing Subsequence
 Problem
Find an increasing subsequence of greatest length
5 2 8 6 3 6 9 7
1. Define the Table
Suppose that 𝑗 < 𝑖 and 𝐷𝑎𝑡𝑎 𝑗 < 𝐷𝑎𝑡𝑎(𝑖).
Then we can add one more element to Increasing Subsequence
whose last element is 𝐷𝑎𝑡𝑎(𝑗)
POSCAT Seminar 1-11
9 July 2014
yougatup
index 0 1 2 3 4 5 6 7
Data 5 2 8 6 3 6 9 7
Table 1 1 2 2 2 3 4 4
Longest Increasing Subsequence
 Problem
Find an increasing subsequence of greatest length
5 2 8 6 3 6 9 7
1. Define the Table
Consider element 6 in the example.
POSCAT Seminar 1-12
9 July 2014
yougatup
index 0 1 2 3 4 5 6 7
Data 5 2 8 6 3 6 9 7
Table 1 1 2 2 2 3 4 4
Longest Increasing Subsequence
 Problem
Find an increasing subsequence of greatest length
5 2 8 6 3 6 9 7
1. Define the Table
We can make a Increasing Subsequence by adding 6 whose last
element is 5. ∴ we can make “5 6”
POSCAT Seminar 1-13
9 July 2014
yougatup
index 0 1 2 3 4 5 6 7
Data 5 2 8 6 3 6 9 7
Table 1 1 2 2 2 3 4 4
Longest Increasing Subsequence
 Problem
Find an increasing subsequence of greatest length
5 2 8 6 3 6 9 7
1. Define the Table
However, we can make another Increasing Subsequence by
considering 2 ! Still the length is 2
POSCAT Seminar 1-14
9 July 2014
yougatup
index 0 1 2 3 4 5 6 7
Data 5 2 8 6 3 6 9 7
Table 1 1 2 2 2 3 4 4
Longest Increasing Subsequence
 Problem
Find an increasing subsequence of greatest length
5 2 8 6 3 6 9 7
1. Define the Table
We can’t make IS with 8 because 8 > 6
POSCAT Seminar 1-15
9 July 2014
yougatup
index 0 1 2 3 4 5 6 7
Data 5 2 8 6 3 6 9 7
Table 1 1 2 2 2 3 4 4
Longest Increasing Subsequence
 Problem
Find an increasing subsequence of greatest length
5 2 8 6 3 6 9 7
1. Define the Table
We can’t
POSCAT Seminar 1-16
9 July 2014
yougatup
index 0 1 2 3 4 5 6 7
Data 5 2 8 6 3 6 9 7
Table 1 1 2 2 2 3 4 4
Longest Increasing Subsequence
 Problem
Find an increasing subsequence of greatest length
5 2 8 6 3 6 9 7
1. Define the Table
We can make ! Therefore, our length is 3.
Note that we considered all the case.
POSCAT Seminar 1-17
9 July 2014
yougatup
index 0 1 2 3 4 5 6 7
Data 5 2 8 6 3 6 9 7
Table 1 1 2 2 2 3 4 4
Longest Increasing Subsequence
 Problem
Find an increasing subsequence of greatest length
5 2 8 6 3 6 9 7
2. Find a recurrence relation
𝑇 𝑖 = max 𝑇 𝑗 + 1 𝑓𝑜𝑟 𝑎𝑙𝑙 𝑗 < 𝑖 & 𝐷𝑎𝑡𝑎 𝑗 < 𝐷𝑎𝑡𝑎(𝑖)
POSCAT Seminar 1-18
9 July 2014
yougatup
index 0 1 2 3 4 5 6 7
Data 5 2 8 6 3 6 9 7
Table 1 1 2 2 2 3 4 4
Longest Increasing Subsequence
 Problem
Find an increasing subsequence of greatest length
5 2 8 6 3 6 9 7
3. Calculate !
You have to think about where the answer is
POSCAT Seminar 1-19
9 July 2014
yougatup
index 0 1 2 3 4 5 6 7
Data 5 2 8 6 3 6 9 7
Table 1 1 2 2 2 3 4 4
Longest Increasing Subsequence
 Problem
Find an increasing subsequence of greatest length
5 2 8 6 3 6 9 7
3. Calculate !
You have to think about where the answer is
It must be the maximum value of whole Table
POSCAT Seminar 1-20
9 July 2014
yougatup
index 0 1 2 3 4 5 6 7
Data 5 2 8 6 3 6 9 7
Table 1 1 2 2 2 3 4 4
Longest Increasing Subsequence
 Problem
Find an increasing subsequence of greatest length
5 2 8 6 3 6 9 7
Well, we can calculate the length of LIS.
Can we find subsequence itself? i.e. “2 3 6 9” in the example.
POSCAT Seminar 1-21
9 July 2014
yougatup
index 0 1 2 3 4 5 6 7
Data 5 2 8 6 3 6 9 7
Table 1 1 2 2 2 3 4 4
Longest Increasing Subsequence
 Problem
Find an increasing subsequence of greatest length
5 2 8 6 3 6 9 7
Well, we can calculate the length of LIS.
Can we find subsequence itself? i.e. “2 3 6 9” in the example.
That’s possible by writing history !
POSCAT Seminar 1-22
9 July 2014
yougatup
index 0 1 2 3 4 5 6 7
Data 5 2 8 6 3 6 9 7
Table 1 1 2 2 2 3 4 4
Longest Increasing Subsequence
 Problem
Find an increasing subsequence of greatest length
5 2 8 6 3 6 9 7
What is the answer on this example ?
POSCAT Seminar 1-23
9 July 2014
yougatup
index 0 1 2 3 4 5 6 7
Data 5 2 8 6 3 6 9 7
Table 1 1 2 2 2 3 4 4
Longest Increasing Subsequence
 Problem
Find an increasing subsequence of greatest length
5 2 8 6 3 6 9 7
What is the answer on this example ?
POSCAT Seminar 1-24
9 July 2014
yougatup
index 0 1 2 3 4 5 6 7
Data 5 2 8 6 3 6 9 7
Table 1 1 2 2 2 3 4 4
Longest Increasing Subsequence
 Problem
Find an increasing subsequence of greatest length
5 2 8 6 3 6 9 7
What is the answer on this example ?
Then the last element of LIS must be 9 because the definition of 𝑇(𝑖)
said that 𝑎𝑖 should be the last element !
POSCAT Seminar 1-25
9 July 2014
yougatup
index 0 1 2 3 4 5 6 7
Data 5 2 8 6 3 6 9 7
Table 1 1 2 2 2 3 4 4
Longest Increasing Subsequence
 Problem
Find an increasing subsequence of greatest length
5 2 8 6 3 6 9 7
Well, 9 is definitely last element of LIS.
How about other elements on LIS ?
POSCAT Seminar 1-26
9 July 2014
yougatup
index 0 1 2 3 4 5 6 7
Data 5 2 8 6 3 6 9 7
Table 1 1 2 2 2 3 4 4
Longest Increasing Subsequence
 Problem
Find an increasing subsequence of greatest length
5 2 8 6 3 6 9 7
Well, 9 is definitely last element of LIS.
How about other elements on LIS ?
𝑇(6) is 4 because we add 9 to the end of IS whose last element is 6
POSCAT Seminar 1-27
9 July 2014
yougatup
index 0 1 2 3 4 5 6 7
Data 5 2 8 6 3 6 9 7
Table 1 1 2 2 2 3 4 4
Longest Increasing Subsequence
 Problem
Find an increasing subsequence of greatest length
5 2 8 6 3 6 9 7
Therefore, 6 have to be located on the left of 9
POSCAT Seminar 1-28
9 July 2014
yougatup
index 0 1 2 3 4 5 6 7
Data 5 2 8 6 3 6 9 7
Table 1 1 2 2 2 3 4 4
Longest Increasing Subsequence
 Problem
Find an increasing subsequence of greatest length
5 2 8 6 3 6 9 7
Therefore, 6 have to be located on the left of 9
Repeat this procedure until we have no former element
POSCAT Seminar 1-29
9 July 2014
yougatup
index 0 1 2 3 4 5 6 7
Data 5 2 8 6 3 6 9 7
Table 1 1 2 2 2 3 4 4
Longest Increasing Subsequence
 Problem
Find an increasing subsequence of greatest length
5 2 8 6 3 6 9 7
Therefore, 6 have to be located on the left of 9
Repeat this procedure until we have no former element
POSCAT Seminar 1-30
9 July 2014
yougatup
index 0 1 2 3 4 5 6 7
Data 5 2 8 6 3 6 9 7
Table 1 1 2 2 2 3 4 4
It has no former element !
Longest Increasing Subsequence
 Problem
Find an increasing subsequence of greatest length
5 2 8 6 3 6 9 7
We call this procedure as “Backtrace”
To implement Backtrace, we have to write down the history.
POSCAT Seminar 1-31
9 July 2014
yougatup
index 0 1 2 3 4 5 6 7
Data 5 2 8 6 3 6 9 7
Table 1 1 2 2 2 3 4 4
Hist. None None 1 1 1 4 5 5
It means that former element of 𝑎5 is 𝑎4 !
Longest Increasing Subsequence
 Problem
Find an increasing subsequence of greatest length
5 2 8 6 3 6 9 7
Implement it . It is very easy to make a stress of yours
POSCAT Seminar 1-32
9 July 2014
yougatup
index 0 1 2 3 4 5 6 7
Data 5 2 8 6 3 6 9 7
Table 1 1 2 2 2 3 4 4
Hist. None None 1 1 1 4 5 5
Longest Common Subsequence
 Problem
Find an Longest Common Subsequence
S N O W Y
S U N N Y
POSCAT Seminar 1-33
9 July 2014
yougatup
Longest Common Subsequence
 Problem
Find an Longest Common Subsequence
S N O W Y
S U N N Y
POSCAT Seminar 1-34
9 July 2014
yougatup
Longest Common Subsequence
 Problem
Find an Longest Common Subsequence
S N O W Y
S U N N Y
1. Define the Table
Give me !
POSCAT Seminar 1-35
9 July 2014
yougatup
Longest Common Subsequence
 Problem
Find an Longest Common Subsequence
S N O W Y
S U N N Y
1. Define the Table
Let 𝑇(𝑖, 𝑗) = The length of LCS between (𝑎1~ 𝑎𝑖) and (𝑏1~ 𝑏𝑗)
POSCAT Seminar 1-36
9 July 2014
yougatup
Longest Common Subsequence
 Problem
Find an Longest Common Subsequence
S N O W Y
S U N N Y
1. Define the Table Fill it manually !
POSCAT Seminar 1-37
9 July 2014
yougatup
S N O W Y
S
U
N
N
Y
Longest Common Subsequence
 Problem
Find an Longest Common Subsequence
S N O W Y
S U N N Y
1. Define the Table How can we feel it ?
POSCAT Seminar 1-38
9 July 2014
yougatup
S N O W Y
S 1 1 1 1 1
U 1 1
N
N
Y
Longest Common Subsequence
 Problem
Find an Longest Common Subsequence
S N O W Y
S U N N Y
Consider this situation.
POSCAT Seminar 1-39
9 July 2014
yougatup
S N O W Y
S 1 1 1 1 1
U 1 1
N
N
Y
Longest Common Subsequence
 Problem
Find an Longest Common Subsequence
S N O W Y
S U N N Y
First of all, we can’t “match” O and U because they are different
POSCAT Seminar 1-40
9 July 2014
yougatup
S N O W Y
S 1 1 1 1 1
U 1 1
N
N
Y
Longest Common Subsequence
 Problem
Find an Longest Common Subsequence
S N O W Y
S U N N Y
Therefore, we can remove one or both element
POSCAT Seminar 1-41
9 July 2014
yougatup
S N O W Y
S 1 1 1 1 1
U 1 1
N
N
Y
Longest Common Subsequence
 Problem
Find an Longest Common Subsequence
S N O W Y
S U N N Y
What is the length of LCS when we remove O ?
POSCAT Seminar 1-42
9 July 2014
yougatup
S N O W Y
S 1 1 1 1 1
U 1 1
N
N
Y
Longest Common Subsequence
 Problem
Find an Longest Common Subsequence
S N O W Y
S U N N Y
What is the length of LCS when we remove O ?
POSCAT Seminar 1-43
9 July 2014
yougatup
S N O W Y
S 1 1 1 1 1
U 1 1
N
N
Y
It knows !
Longest Common Subsequence
 Problem
Find an Longest Common Subsequence
S N O W Y
S U N N Y
What is the length of LCS when we remove U ?
POSCAT Seminar 1-44
9 July 2014
yougatup
S N O W Y
S 1 1 1 1 1
U 1 1
N
N
Y
Longest Common Subsequence
 Problem
Find an Longest Common Subsequence
S N O W Y
S U N N Y
What is the length of LCS when we remove U ?
POSCAT Seminar 1-45
9 July 2014
yougatup
S N O W Y
S 1 1 1 1 1
U 1 1
N
N
Y
It has !
Longest Common Subsequence
 Problem
Find an Longest Common Subsequence
S N O W Y
S U N N Y
Therefore, the value of this entry is 1
POSCAT Seminar 1-46
9 July 2014
yougatup
S N O W Y
S 1 1 1 1 1
U 1 1 1
N
N
Y
Longest Common Subsequence
 Problem
Find an Longest Common Subsequence
S N O W Y
S U N N Y
How about this situation ?
POSCAT Seminar 1-47
9 July 2014
yougatup
S N O W Y
S 1 1 1 1 1
U 1 1 1 1 1
N 1
N
Y
Longest Common Subsequence
 Problem
Find an Longest Common Subsequence
S N O W Y
S U N N Y
We can match N! because they are the same
POSCAT Seminar 1-48
9 July 2014
yougatup
S N O W Y
S 1 1 1 1 1
U 1 1 1 1 1
N 1
N
Y
Longest Common Subsequence
 Problem
Find an Longest Common Subsequence
S N O W Y
S U N N Y
Then, the LCS must be (LCS between “S” and “SU”) + N
POSCAT Seminar 1-49
9 July 2014
yougatup
S N O W Y
S 1 1 1 1 1
U 1 1 1 1 1
N 1
N
Y
Longest Common Subsequence
 Problem
Find an Longest Common Subsequence
S N O W Y
S U N N Y
Therefore, we get SN. In addition, the value of this entry is 2
POSCAT Seminar 1-50
9 July 2014
yougatup
S N O W Y
S 1 1 1 1 1
U 1 1 1 1 1
N 1 2
N
Y
Longest Common Subsequence
 Problem
Find an Longest Common Subsequence
S N O W Y
S U N N Y
Can you see the recurrence relation ?
POSCAT Seminar 1-51
9 July 2014
yougatup
S N O W Y
S 1 1 1 1 1
U 1 1 1 1 1
N 1 2 2 2 2
N 1 2 2 2 2
Y 1 2 2 2 3
Longest Common Subsequence
 Problem
Find an Longest Common Subsequence
S N O W Y
S U N N Y
2. Find a recurrence relation
POSCAT Seminar 1-52
9 July 2014
yougatup
Longest Common Subsequence
 Problem
Find an Longest Common Subsequence
S N O W Y
S U N N Y
2. Find a recurrence relation
𝑇 𝑖, 𝑗 = 𝑇 𝑖 − 1, 𝑗 − 1 + 1 𝑖𝑓 𝑎𝑖 = 𝑏𝑗
max 𝑇 𝑖 − 1, 𝑗 , 𝑇 𝑖, 𝑗 − 1 𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒
POSCAT Seminar 1-53
9 July 2014
yougatup
Longest Common Subsequence
 Problem
Find an Longest Common Subsequence
S N O W Y
S U N N Y
3. Calculate !
Think about backtrace. It will be easy if you understand DP well.
POSCAT Seminar 1-54
9 July 2014
yougatup
Dynamic Programming
 Remember. 3 step is enough.
− The first step is the most important thing. Finding the
recurrence relation is not that hard commonly.
− I showed somewhat detail explanation of solving procedure
because it is first time to you
− From the next time, I will just let you know what the definition
of Table and the recurrent relation is
 Please solve all the problem
POSCAT Seminar 1-55
9 July 2014
yougatup

More Related Content

Viewers also liked

Analytical Solution Of Schrödinger Equation With Mie–Type Potential Using Fac...
Analytical Solution Of Schrödinger Equation With Mie–Type Potential Using Fac...Analytical Solution Of Schrödinger Equation With Mie–Type Potential Using Fac...
Analytical Solution Of Schrödinger Equation With Mie–Type Potential Using Fac...ijrap
 
Uuidはどこまでuuidか試してみた
Uuidはどこまでuuidか試してみたUuidはどこまでuuidか試してみた
Uuidはどこまでuuidか試してみたYu Yamada
 
8. Graph - Data Structures using C++ by Varsha Patil
8. Graph - Data Structures using C++ by Varsha Patil8. Graph - Data Structures using C++ by Varsha Patil
8. Graph - Data Structures using C++ by Varsha Patilwidespreadpromotion
 
Dijkstra s algorithm
Dijkstra s algorithmDijkstra s algorithm
Dijkstra s algorithmmansab MIRZA
 
1. Fundamental Concept - Data Structures using C++ by Varsha Patil
1. Fundamental Concept - Data Structures using C++ by Varsha Patil1. Fundamental Concept - Data Structures using C++ by Varsha Patil
1. Fundamental Concept - Data Structures using C++ by Varsha Patilwidespreadpromotion
 
Divide and conquer - Quick sort
Divide and conquer - Quick sortDivide and conquer - Quick sort
Divide and conquer - Quick sortMadhu Bala
 
Attributes, reflection, and dynamic programming
Attributes, reflection, and dynamic programmingAttributes, reflection, and dynamic programming
Attributes, reflection, and dynamic programmingLearnNowOnline
 
Convex Hull - Chan's Algorithm O(n log h) - Presentation by Yitian Huang and ...
Convex Hull - Chan's Algorithm O(n log h) - Presentation by Yitian Huang and ...Convex Hull - Chan's Algorithm O(n log h) - Presentation by Yitian Huang and ...
Convex Hull - Chan's Algorithm O(n log h) - Presentation by Yitian Huang and ...Amrinder Arora
 
Divide and Conquer - Part 1
Divide and Conquer - Part 1Divide and Conquer - Part 1
Divide and Conquer - Part 1Amrinder Arora
 
AVR_Course_Day1 basic electronics
AVR_Course_Day1 basic electronicsAVR_Course_Day1 basic electronics
AVR_Course_Day1 basic electronicsMohamed Ali
 

Viewers also liked (15)

Analytical Solution Of Schrödinger Equation With Mie–Type Potential Using Fac...
Analytical Solution Of Schrödinger Equation With Mie–Type Potential Using Fac...Analytical Solution Of Schrödinger Equation With Mie–Type Potential Using Fac...
Analytical Solution Of Schrödinger Equation With Mie–Type Potential Using Fac...
 
Proyecto alegebra andres pastaz 2
Proyecto alegebra andres pastaz 2Proyecto alegebra andres pastaz 2
Proyecto alegebra andres pastaz 2
 
Uuidはどこまでuuidか試してみた
Uuidはどこまでuuidか試してみたUuidはどこまでuuidか試してみた
Uuidはどこまでuuidか試してみた
 
The Right Type of Cloud Messaging
The Right Type of Cloud MessagingThe Right Type of Cloud Messaging
The Right Type of Cloud Messaging
 
8. Graph - Data Structures using C++ by Varsha Patil
8. Graph - Data Structures using C++ by Varsha Patil8. Graph - Data Structures using C++ by Varsha Patil
8. Graph - Data Structures using C++ by Varsha Patil
 
Dijkstra s algorithm
Dijkstra s algorithmDijkstra s algorithm
Dijkstra s algorithm
 
Docker超入門
Docker超入門Docker超入門
Docker超入門
 
DP
DPDP
DP
 
1. Fundamental Concept - Data Structures using C++ by Varsha Patil
1. Fundamental Concept - Data Structures using C++ by Varsha Patil1. Fundamental Concept - Data Structures using C++ by Varsha Patil
1. Fundamental Concept - Data Structures using C++ by Varsha Patil
 
Divide and conquer - Quick sort
Divide and conquer - Quick sortDivide and conquer - Quick sort
Divide and conquer - Quick sort
 
Attributes, reflection, and dynamic programming
Attributes, reflection, and dynamic programmingAttributes, reflection, and dynamic programming
Attributes, reflection, and dynamic programming
 
Convex Hull - Chan's Algorithm O(n log h) - Presentation by Yitian Huang and ...
Convex Hull - Chan's Algorithm O(n log h) - Presentation by Yitian Huang and ...Convex Hull - Chan's Algorithm O(n log h) - Presentation by Yitian Huang and ...
Convex Hull - Chan's Algorithm O(n log h) - Presentation by Yitian Huang and ...
 
Divide and Conquer - Part 1
Divide and Conquer - Part 1Divide and Conquer - Part 1
Divide and Conquer - Part 1
 
(floyd's algm)
(floyd's algm)(floyd's algm)
(floyd's algm)
 
AVR_Course_Day1 basic electronics
AVR_Course_Day1 basic electronicsAVR_Course_Day1 basic electronics
AVR_Course_Day1 basic electronics
 

Similar to Poscat seminar 7

An alternative learning experience in transition level mathematics
An alternative learning experience in transition level mathematicsAn alternative learning experience in transition level mathematics
An alternative learning experience in transition level mathematicsDann Mallet
 
Andrew Daws - Final Project Report
Andrew Daws - Final Project ReportAndrew Daws - Final Project Report
Andrew Daws - Final Project ReportAndrew Daws
 
Poscat seminar 3-1
Poscat seminar 3-1Poscat seminar 3-1
Poscat seminar 3-1Hyungyu Shin
 
TEXTBOOK ON MATHEMATICAL ECONOMICS FOR CU , BU CALCUTTA , SOLVED EXERCISES , ...
TEXTBOOK ON MATHEMATICAL ECONOMICS FOR CU , BU CALCUTTA , SOLVED EXERCISES , ...TEXTBOOK ON MATHEMATICAL ECONOMICS FOR CU , BU CALCUTTA , SOLVED EXERCISES , ...
TEXTBOOK ON MATHEMATICAL ECONOMICS FOR CU , BU CALCUTTA , SOLVED EXERCISES , ...SOURAV DAS
 
Dobson michael pag 52 106
Dobson michael pag 52 106Dobson michael pag 52 106
Dobson michael pag 52 106alextm76
 
#ITsubbotnik Spring 2017: Mikhail Khludnev "Search like %SQL%"
#ITsubbotnik Spring 2017: Mikhail Khludnev "Search like %SQL%"#ITsubbotnik Spring 2017: Mikhail Khludnev "Search like %SQL%"
#ITsubbotnik Spring 2017: Mikhail Khludnev "Search like %SQL%"epamspb
 
Power Full Exposition
Power Full ExpositionPower Full Exposition
Power Full ExpositionHeesu Hwang
 
Syam critical path cpa
Syam critical path cpaSyam critical path cpa
Syam critical path cpasyamputra
 
Predict saturated thickness using tensor board visualization
Predict saturated thickness using tensor board visualizationPredict saturated thickness using tensor board visualization
Predict saturated thickness using tensor board visualizationVinh Nguyen
 
BSOP 330 TUTOR Real Education / bsop330tutor.com
BSOP 330 TUTOR Real Education / bsop330tutor.comBSOP 330 TUTOR Real Education / bsop330tutor.com
BSOP 330 TUTOR Real Education / bsop330tutor.communnaq7
 
The Scientific Method
The Scientific MethodThe Scientific Method
The Scientific Methodtscheuch
 

Similar to Poscat seminar 7 (20)

Poscat seminar 8
Poscat seminar 8Poscat seminar 8
Poscat seminar 8
 
Poscat seminar 11
Poscat seminar 11Poscat seminar 11
Poscat seminar 11
 
Poscat seminar 2
Poscat seminar 2Poscat seminar 2
Poscat seminar 2
 
An alternative learning experience in transition level mathematics
An alternative learning experience in transition level mathematicsAn alternative learning experience in transition level mathematics
An alternative learning experience in transition level mathematics
 
Poscat seminar 10
Poscat seminar 10Poscat seminar 10
Poscat seminar 10
 
Andrew Daws - Final Project Report
Andrew Daws - Final Project ReportAndrew Daws - Final Project Report
Andrew Daws - Final Project Report
 
Poscat seminar 3-1
Poscat seminar 3-1Poscat seminar 3-1
Poscat seminar 3-1
 
Pert2
Pert2Pert2
Pert2
 
TEXTBOOK ON MATHEMATICAL ECONOMICS FOR CU , BU CALCUTTA , SOLVED EXERCISES , ...
TEXTBOOK ON MATHEMATICAL ECONOMICS FOR CU , BU CALCUTTA , SOLVED EXERCISES , ...TEXTBOOK ON MATHEMATICAL ECONOMICS FOR CU , BU CALCUTTA , SOLVED EXERCISES , ...
TEXTBOOK ON MATHEMATICAL ECONOMICS FOR CU , BU CALCUTTA , SOLVED EXERCISES , ...
 
Poscat seminar 6
Poscat seminar 6Poscat seminar 6
Poscat seminar 6
 
Dobson michael pag 52 106
Dobson michael pag 52 106Dobson michael pag 52 106
Dobson michael pag 52 106
 
#ITsubbotnik Spring 2017: Mikhail Khludnev "Search like %SQL%"
#ITsubbotnik Spring 2017: Mikhail Khludnev "Search like %SQL%"#ITsubbotnik Spring 2017: Mikhail Khludnev "Search like %SQL%"
#ITsubbotnik Spring 2017: Mikhail Khludnev "Search like %SQL%"
 
Power Full Exposition
Power Full ExpositionPower Full Exposition
Power Full Exposition
 
Poscat seminar 9
Poscat seminar 9Poscat seminar 9
Poscat seminar 9
 
NATE_Oct17_2015_Schwieterman
NATE_Oct17_2015_SchwietermanNATE_Oct17_2015_Schwieterman
NATE_Oct17_2015_Schwieterman
 
Syam critical path cpa
Syam critical path cpaSyam critical path cpa
Syam critical path cpa
 
Predict saturated thickness using tensor board visualization
Predict saturated thickness using tensor board visualizationPredict saturated thickness using tensor board visualization
Predict saturated thickness using tensor board visualization
 
Poscat seminar 5
Poscat seminar 5Poscat seminar 5
Poscat seminar 5
 
BSOP 330 TUTOR Real Education / bsop330tutor.com
BSOP 330 TUTOR Real Education / bsop330tutor.comBSOP 330 TUTOR Real Education / bsop330tutor.com
BSOP 330 TUTOR Real Education / bsop330tutor.com
 
The Scientific Method
The Scientific MethodThe Scientific Method
The Scientific Method
 

Recently uploaded

2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptxMaritesTamaniVerdade
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxEsquimalt MFRC
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...Nguyen Thanh Tu Collection
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxUmeshTimilsina1
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxPooja Bhuva
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17Celine George
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxDr. Ravikiran H M Gowda
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxJisc
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Pooja Bhuva
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024Elizabeth Walsh
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsKarakKing
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 

Recently uploaded (20)

2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptx
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 

Poscat seminar 7

  • 1. POSCAT Seminar 7 : Dynamic Programming 1 yougatup @ POSCAT 1
  • 2. Topic  Topic today − Dynamic Programming • Basic Concept • Longest Increasing Subsequence • Longest Common Subsequence POSCAT Seminar 1-2 9 July 2014 yougatup
  • 3. Dynamic Programming  Problem Solving Paradigm − Identifying a collection of subproblems − Tackling them one by one • smallest first • using the answer already calculated to help figure out the larger ones • until the whole problem is solved  One of the most prominent issue − You can be familiar with PS with Dynamic Programming − There are so many issues to cover POSCAT Seminar 1-3 9 July 2014 yougatup
  • 4. Dynamic Programming  Procedure 1. Define the Table 2. Find recurrence relation 3. Calculate ! POSCAT Seminar 1-4 9 July 2014 yougatup
  • 5. Longest Increasing Subsequence  Problem Find an increasing subsequence of greatest length 5 2 8 6 3 6 9 7 POSCAT Seminar 1-5 9 July 2014 yougatup
  • 6. Longest Increasing Subsequence  Problem Find an increasing subsequence of greatest length 5 2 8 6 3 6 9 7 POSCAT Seminar 1-6 9 July 2014 yougatup
  • 7. Longest Increasing Subsequence  Problem Find an increasing subsequence of greatest length 5 2 8 6 3 6 9 7 1. Define the Table POSCAT Seminar 1-7 9 July 2014 yougatup
  • 8. Longest Increasing Subsequence  Problem Find an increasing subsequence of greatest length 5 2 8 6 3 6 9 7 1. Define the Table Let 𝑇(𝑖) = The length of LIS when 𝑎𝑖 is the last element ∴ 𝑎𝑖 have to be last element of subsequence POSCAT Seminar 1-8 9 July 2014 yougatup
  • 9. Longest Increasing Subsequence  Problem Find an increasing subsequence of greatest length 5 2 8 6 3 6 9 7 1. Define the Table You can fill the table manually. What is the answer ? POSCAT Seminar 1-9 9 July 2014 yougatup index 0 1 2 3 4 5 6 7 Data 5 2 8 6 3 6 9 7 Table 1 1 2 2 2 3 4 4
  • 10. Longest Increasing Subsequence  Problem Find an increasing subsequence of greatest length 5 2 8 6 3 6 9 7 1. Define the Table Can you see the recurrence relation on 𝑇 ? POSCAT Seminar 1-10 9 July 2014 yougatup index 0 1 2 3 4 5 6 7 Data 5 2 8 6 3 6 9 7 Table 1 1 2 2 2 3 4 4
  • 11. Longest Increasing Subsequence  Problem Find an increasing subsequence of greatest length 5 2 8 6 3 6 9 7 1. Define the Table Suppose that 𝑗 < 𝑖 and 𝐷𝑎𝑡𝑎 𝑗 < 𝐷𝑎𝑡𝑎(𝑖). Then we can add one more element to Increasing Subsequence whose last element is 𝐷𝑎𝑡𝑎(𝑗) POSCAT Seminar 1-11 9 July 2014 yougatup index 0 1 2 3 4 5 6 7 Data 5 2 8 6 3 6 9 7 Table 1 1 2 2 2 3 4 4
  • 12. Longest Increasing Subsequence  Problem Find an increasing subsequence of greatest length 5 2 8 6 3 6 9 7 1. Define the Table Consider element 6 in the example. POSCAT Seminar 1-12 9 July 2014 yougatup index 0 1 2 3 4 5 6 7 Data 5 2 8 6 3 6 9 7 Table 1 1 2 2 2 3 4 4
  • 13. Longest Increasing Subsequence  Problem Find an increasing subsequence of greatest length 5 2 8 6 3 6 9 7 1. Define the Table We can make a Increasing Subsequence by adding 6 whose last element is 5. ∴ we can make “5 6” POSCAT Seminar 1-13 9 July 2014 yougatup index 0 1 2 3 4 5 6 7 Data 5 2 8 6 3 6 9 7 Table 1 1 2 2 2 3 4 4
  • 14. Longest Increasing Subsequence  Problem Find an increasing subsequence of greatest length 5 2 8 6 3 6 9 7 1. Define the Table However, we can make another Increasing Subsequence by considering 2 ! Still the length is 2 POSCAT Seminar 1-14 9 July 2014 yougatup index 0 1 2 3 4 5 6 7 Data 5 2 8 6 3 6 9 7 Table 1 1 2 2 2 3 4 4
  • 15. Longest Increasing Subsequence  Problem Find an increasing subsequence of greatest length 5 2 8 6 3 6 9 7 1. Define the Table We can’t make IS with 8 because 8 > 6 POSCAT Seminar 1-15 9 July 2014 yougatup index 0 1 2 3 4 5 6 7 Data 5 2 8 6 3 6 9 7 Table 1 1 2 2 2 3 4 4
  • 16. Longest Increasing Subsequence  Problem Find an increasing subsequence of greatest length 5 2 8 6 3 6 9 7 1. Define the Table We can’t POSCAT Seminar 1-16 9 July 2014 yougatup index 0 1 2 3 4 5 6 7 Data 5 2 8 6 3 6 9 7 Table 1 1 2 2 2 3 4 4
  • 17. Longest Increasing Subsequence  Problem Find an increasing subsequence of greatest length 5 2 8 6 3 6 9 7 1. Define the Table We can make ! Therefore, our length is 3. Note that we considered all the case. POSCAT Seminar 1-17 9 July 2014 yougatup index 0 1 2 3 4 5 6 7 Data 5 2 8 6 3 6 9 7 Table 1 1 2 2 2 3 4 4
  • 18. Longest Increasing Subsequence  Problem Find an increasing subsequence of greatest length 5 2 8 6 3 6 9 7 2. Find a recurrence relation 𝑇 𝑖 = max 𝑇 𝑗 + 1 𝑓𝑜𝑟 𝑎𝑙𝑙 𝑗 < 𝑖 & 𝐷𝑎𝑡𝑎 𝑗 < 𝐷𝑎𝑡𝑎(𝑖) POSCAT Seminar 1-18 9 July 2014 yougatup index 0 1 2 3 4 5 6 7 Data 5 2 8 6 3 6 9 7 Table 1 1 2 2 2 3 4 4
  • 19. Longest Increasing Subsequence  Problem Find an increasing subsequence of greatest length 5 2 8 6 3 6 9 7 3. Calculate ! You have to think about where the answer is POSCAT Seminar 1-19 9 July 2014 yougatup index 0 1 2 3 4 5 6 7 Data 5 2 8 6 3 6 9 7 Table 1 1 2 2 2 3 4 4
  • 20. Longest Increasing Subsequence  Problem Find an increasing subsequence of greatest length 5 2 8 6 3 6 9 7 3. Calculate ! You have to think about where the answer is It must be the maximum value of whole Table POSCAT Seminar 1-20 9 July 2014 yougatup index 0 1 2 3 4 5 6 7 Data 5 2 8 6 3 6 9 7 Table 1 1 2 2 2 3 4 4
  • 21. Longest Increasing Subsequence  Problem Find an increasing subsequence of greatest length 5 2 8 6 3 6 9 7 Well, we can calculate the length of LIS. Can we find subsequence itself? i.e. “2 3 6 9” in the example. POSCAT Seminar 1-21 9 July 2014 yougatup index 0 1 2 3 4 5 6 7 Data 5 2 8 6 3 6 9 7 Table 1 1 2 2 2 3 4 4
  • 22. Longest Increasing Subsequence  Problem Find an increasing subsequence of greatest length 5 2 8 6 3 6 9 7 Well, we can calculate the length of LIS. Can we find subsequence itself? i.e. “2 3 6 9” in the example. That’s possible by writing history ! POSCAT Seminar 1-22 9 July 2014 yougatup index 0 1 2 3 4 5 6 7 Data 5 2 8 6 3 6 9 7 Table 1 1 2 2 2 3 4 4
  • 23. Longest Increasing Subsequence  Problem Find an increasing subsequence of greatest length 5 2 8 6 3 6 9 7 What is the answer on this example ? POSCAT Seminar 1-23 9 July 2014 yougatup index 0 1 2 3 4 5 6 7 Data 5 2 8 6 3 6 9 7 Table 1 1 2 2 2 3 4 4
  • 24. Longest Increasing Subsequence  Problem Find an increasing subsequence of greatest length 5 2 8 6 3 6 9 7 What is the answer on this example ? POSCAT Seminar 1-24 9 July 2014 yougatup index 0 1 2 3 4 5 6 7 Data 5 2 8 6 3 6 9 7 Table 1 1 2 2 2 3 4 4
  • 25. Longest Increasing Subsequence  Problem Find an increasing subsequence of greatest length 5 2 8 6 3 6 9 7 What is the answer on this example ? Then the last element of LIS must be 9 because the definition of 𝑇(𝑖) said that 𝑎𝑖 should be the last element ! POSCAT Seminar 1-25 9 July 2014 yougatup index 0 1 2 3 4 5 6 7 Data 5 2 8 6 3 6 9 7 Table 1 1 2 2 2 3 4 4
  • 26. Longest Increasing Subsequence  Problem Find an increasing subsequence of greatest length 5 2 8 6 3 6 9 7 Well, 9 is definitely last element of LIS. How about other elements on LIS ? POSCAT Seminar 1-26 9 July 2014 yougatup index 0 1 2 3 4 5 6 7 Data 5 2 8 6 3 6 9 7 Table 1 1 2 2 2 3 4 4
  • 27. Longest Increasing Subsequence  Problem Find an increasing subsequence of greatest length 5 2 8 6 3 6 9 7 Well, 9 is definitely last element of LIS. How about other elements on LIS ? 𝑇(6) is 4 because we add 9 to the end of IS whose last element is 6 POSCAT Seminar 1-27 9 July 2014 yougatup index 0 1 2 3 4 5 6 7 Data 5 2 8 6 3 6 9 7 Table 1 1 2 2 2 3 4 4
  • 28. Longest Increasing Subsequence  Problem Find an increasing subsequence of greatest length 5 2 8 6 3 6 9 7 Therefore, 6 have to be located on the left of 9 POSCAT Seminar 1-28 9 July 2014 yougatup index 0 1 2 3 4 5 6 7 Data 5 2 8 6 3 6 9 7 Table 1 1 2 2 2 3 4 4
  • 29. Longest Increasing Subsequence  Problem Find an increasing subsequence of greatest length 5 2 8 6 3 6 9 7 Therefore, 6 have to be located on the left of 9 Repeat this procedure until we have no former element POSCAT Seminar 1-29 9 July 2014 yougatup index 0 1 2 3 4 5 6 7 Data 5 2 8 6 3 6 9 7 Table 1 1 2 2 2 3 4 4
  • 30. Longest Increasing Subsequence  Problem Find an increasing subsequence of greatest length 5 2 8 6 3 6 9 7 Therefore, 6 have to be located on the left of 9 Repeat this procedure until we have no former element POSCAT Seminar 1-30 9 July 2014 yougatup index 0 1 2 3 4 5 6 7 Data 5 2 8 6 3 6 9 7 Table 1 1 2 2 2 3 4 4 It has no former element !
  • 31. Longest Increasing Subsequence  Problem Find an increasing subsequence of greatest length 5 2 8 6 3 6 9 7 We call this procedure as “Backtrace” To implement Backtrace, we have to write down the history. POSCAT Seminar 1-31 9 July 2014 yougatup index 0 1 2 3 4 5 6 7 Data 5 2 8 6 3 6 9 7 Table 1 1 2 2 2 3 4 4 Hist. None None 1 1 1 4 5 5 It means that former element of 𝑎5 is 𝑎4 !
  • 32. Longest Increasing Subsequence  Problem Find an increasing subsequence of greatest length 5 2 8 6 3 6 9 7 Implement it . It is very easy to make a stress of yours POSCAT Seminar 1-32 9 July 2014 yougatup index 0 1 2 3 4 5 6 7 Data 5 2 8 6 3 6 9 7 Table 1 1 2 2 2 3 4 4 Hist. None None 1 1 1 4 5 5
  • 33. Longest Common Subsequence  Problem Find an Longest Common Subsequence S N O W Y S U N N Y POSCAT Seminar 1-33 9 July 2014 yougatup
  • 34. Longest Common Subsequence  Problem Find an Longest Common Subsequence S N O W Y S U N N Y POSCAT Seminar 1-34 9 July 2014 yougatup
  • 35. Longest Common Subsequence  Problem Find an Longest Common Subsequence S N O W Y S U N N Y 1. Define the Table Give me ! POSCAT Seminar 1-35 9 July 2014 yougatup
  • 36. Longest Common Subsequence  Problem Find an Longest Common Subsequence S N O W Y S U N N Y 1. Define the Table Let 𝑇(𝑖, 𝑗) = The length of LCS between (𝑎1~ 𝑎𝑖) and (𝑏1~ 𝑏𝑗) POSCAT Seminar 1-36 9 July 2014 yougatup
  • 37. Longest Common Subsequence  Problem Find an Longest Common Subsequence S N O W Y S U N N Y 1. Define the Table Fill it manually ! POSCAT Seminar 1-37 9 July 2014 yougatup S N O W Y S U N N Y
  • 38. Longest Common Subsequence  Problem Find an Longest Common Subsequence S N O W Y S U N N Y 1. Define the Table How can we feel it ? POSCAT Seminar 1-38 9 July 2014 yougatup S N O W Y S 1 1 1 1 1 U 1 1 N N Y
  • 39. Longest Common Subsequence  Problem Find an Longest Common Subsequence S N O W Y S U N N Y Consider this situation. POSCAT Seminar 1-39 9 July 2014 yougatup S N O W Y S 1 1 1 1 1 U 1 1 N N Y
  • 40. Longest Common Subsequence  Problem Find an Longest Common Subsequence S N O W Y S U N N Y First of all, we can’t “match” O and U because they are different POSCAT Seminar 1-40 9 July 2014 yougatup S N O W Y S 1 1 1 1 1 U 1 1 N N Y
  • 41. Longest Common Subsequence  Problem Find an Longest Common Subsequence S N O W Y S U N N Y Therefore, we can remove one or both element POSCAT Seminar 1-41 9 July 2014 yougatup S N O W Y S 1 1 1 1 1 U 1 1 N N Y
  • 42. Longest Common Subsequence  Problem Find an Longest Common Subsequence S N O W Y S U N N Y What is the length of LCS when we remove O ? POSCAT Seminar 1-42 9 July 2014 yougatup S N O W Y S 1 1 1 1 1 U 1 1 N N Y
  • 43. Longest Common Subsequence  Problem Find an Longest Common Subsequence S N O W Y S U N N Y What is the length of LCS when we remove O ? POSCAT Seminar 1-43 9 July 2014 yougatup S N O W Y S 1 1 1 1 1 U 1 1 N N Y It knows !
  • 44. Longest Common Subsequence  Problem Find an Longest Common Subsequence S N O W Y S U N N Y What is the length of LCS when we remove U ? POSCAT Seminar 1-44 9 July 2014 yougatup S N O W Y S 1 1 1 1 1 U 1 1 N N Y
  • 45. Longest Common Subsequence  Problem Find an Longest Common Subsequence S N O W Y S U N N Y What is the length of LCS when we remove U ? POSCAT Seminar 1-45 9 July 2014 yougatup S N O W Y S 1 1 1 1 1 U 1 1 N N Y It has !
  • 46. Longest Common Subsequence  Problem Find an Longest Common Subsequence S N O W Y S U N N Y Therefore, the value of this entry is 1 POSCAT Seminar 1-46 9 July 2014 yougatup S N O W Y S 1 1 1 1 1 U 1 1 1 N N Y
  • 47. Longest Common Subsequence  Problem Find an Longest Common Subsequence S N O W Y S U N N Y How about this situation ? POSCAT Seminar 1-47 9 July 2014 yougatup S N O W Y S 1 1 1 1 1 U 1 1 1 1 1 N 1 N Y
  • 48. Longest Common Subsequence  Problem Find an Longest Common Subsequence S N O W Y S U N N Y We can match N! because they are the same POSCAT Seminar 1-48 9 July 2014 yougatup S N O W Y S 1 1 1 1 1 U 1 1 1 1 1 N 1 N Y
  • 49. Longest Common Subsequence  Problem Find an Longest Common Subsequence S N O W Y S U N N Y Then, the LCS must be (LCS between “S” and “SU”) + N POSCAT Seminar 1-49 9 July 2014 yougatup S N O W Y S 1 1 1 1 1 U 1 1 1 1 1 N 1 N Y
  • 50. Longest Common Subsequence  Problem Find an Longest Common Subsequence S N O W Y S U N N Y Therefore, we get SN. In addition, the value of this entry is 2 POSCAT Seminar 1-50 9 July 2014 yougatup S N O W Y S 1 1 1 1 1 U 1 1 1 1 1 N 1 2 N Y
  • 51. Longest Common Subsequence  Problem Find an Longest Common Subsequence S N O W Y S U N N Y Can you see the recurrence relation ? POSCAT Seminar 1-51 9 July 2014 yougatup S N O W Y S 1 1 1 1 1 U 1 1 1 1 1 N 1 2 2 2 2 N 1 2 2 2 2 Y 1 2 2 2 3
  • 52. Longest Common Subsequence  Problem Find an Longest Common Subsequence S N O W Y S U N N Y 2. Find a recurrence relation POSCAT Seminar 1-52 9 July 2014 yougatup
  • 53. Longest Common Subsequence  Problem Find an Longest Common Subsequence S N O W Y S U N N Y 2. Find a recurrence relation 𝑇 𝑖, 𝑗 = 𝑇 𝑖 − 1, 𝑗 − 1 + 1 𝑖𝑓 𝑎𝑖 = 𝑏𝑗 max 𝑇 𝑖 − 1, 𝑗 , 𝑇 𝑖, 𝑗 − 1 𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒 POSCAT Seminar 1-53 9 July 2014 yougatup
  • 54. Longest Common Subsequence  Problem Find an Longest Common Subsequence S N O W Y S U N N Y 3. Calculate ! Think about backtrace. It will be easy if you understand DP well. POSCAT Seminar 1-54 9 July 2014 yougatup
  • 55. Dynamic Programming  Remember. 3 step is enough. − The first step is the most important thing. Finding the recurrence relation is not that hard commonly. − I showed somewhat detail explanation of solving procedure because it is first time to you − From the next time, I will just let you know what the definition of Table and the recurrent relation is  Please solve all the problem POSCAT Seminar 1-55 9 July 2014 yougatup