SlideShare a Scribd company logo
[object Object],[object Object],[object Object]
Dynamic programming ,[object Object],[object Object],[object Object]
Longest Common Subsequence (LCS) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
LCS Algorithm ,[object Object],[object Object],[object Object],[object Object]
LCS Algorithm ,[object Object],[object Object],[object Object],[object Object]
LCS recursive solution ,[object Object],[object Object],[object Object]
LCS recursive solution ,[object Object],[object Object]
LCS recursive solution ,[object Object],[object Object],Why not just take the length of LCS(X i-1 , Y j-1 ) ?
LCS Length Algorithm ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
LCS Example ,[object Object],[object Object],[object Object],LCS(X, Y) = BCB X = A  B   C   B Y =  B  D  C  A  B What is the Longest Common Subsequence  of X and Y?
LCS Example (0) j  0  1  2  3  4  5  0 1 2 3 4 i Xi A B C B Yj B B A C D X = ABCB;  m = |X| = 4 Y = BDCAB; n = |Y| = 5 Allocate array c[5,4] ABCB BDCAB
LCS Example (1) j  0  1  2  3  4  5  0 1 2 3 4 i Xi A B C B Yj B B A C D 0 0 0 0 0 0 0 0 0 0 for i = 1 to m  c[i,0] = 0  for j = 1 to n  c[0,j] = 0 ABCB BDCAB
LCS Example (2) j  0  1   2  3  4  5  0 1 2 3 4 i Xi A B C B Yj B B A C D 0 0 0 0 0 0 0 0 0 0 if ( X i  == Y j  ) c[i,j] = c[i-1,j-1] + 1 else c[i,j] = max( c[i-1,j], c[i,j-1]  ) 0 A BCB B DCAB
LCS Example (3) j  0  1  2  3  4  5  0 1 2 3 4 i Xi A B C B Yj B B A C D 0 0 0 0 0 0 0 0 0 0 if ( X i  == Y j  ) c[i,j] = c[i-1,j-1] + 1 else c[i,j] = max( c[i-1,j], c[i,j-1] ) 0 0 0 A BCB B DC AB
LCS Example (4) j  0  1  2  3  4   5  0 1 2 3 4 i Xi A B C B Yj B B A C D 0 0 0 0 0 0 0 0 0 0 if ( X i  == Y j  ) c[i,j] = c[i-1,j-1] + 1 else c[i,j] = max( c[i-1,j], c[i,j-1] ) 0 0 0 1 A BCB BDC A B
LCS Example (5) j  0  1  2  3  4  5  0 1 2 3 4 i Xi A B C B Yj B B A C D 0 0 0 0 0 0 0 0 0 0 if ( X i  == Y j  ) c[i,j] = c[i-1,j-1] + 1 else c[i,j] = max( c[i-1,j], c[i,j-1] ) 0 0 0 1 1 A BCB BDCA B
LCS Example (6) j  0  1   2  3  4  5  0 1 2 3 4 i Xi A B C B Yj B B A C D 0 0 0 0 0 0 0 0 0 0 if ( X i  == Y j  ) c[i,j] = c[i-1,j-1] + 1 else c[i,j] = max( c[i-1,j], c[i,j-1] ) 0 0 1 0 1 1 A B CB B DCAB
LCS Example (7) j  0  1  2  3  4   5  0 1 2 3 4 i Xi A B C B Yj B B A C D 0 0 0 0 0 0 0 0 0 0 if ( X i  == Y j  ) c[i,j] = c[i-1,j-1] + 1 else c[i,j] = max( c[i-1,j], c[i,j-1] ) 1 0 0 0 1 1 1 1 1 A B CB B DCA B
LCS Example (8) j  0  1  2  3  4  5   0 1 2 3 4 i Xi A B C B Yj B B A C D 0 0 0 0 0 0 0 0 0 0 if ( X i  == Y j  ) c[i,j] = c[i-1,j-1] + 1 else c[i,j] = max( c[i-1,j], c[i,j-1] ) 1 0 0 0 1 1 1 1 1 2 A B CB BDCA B
LCS Example (10) j  0  1  2   3  4  5  0 1 2 3 4 i Xi A B C B Yj B B A C D 0 0 0 0 0 0 0 0 0 0 if ( X i  == Y j  ) c[i,j] = c[i-1,j-1] + 1 else c[i,j] = max( c[i-1,j], c[i,j-1] ) 1 0 0 0 1 2 1 1 1 1 1 1 AB C B BD CAB
LCS Example (11) j  0  1  2  3   4  5  0 1 2 3 4 i Xi A B C B Yj B B A C D 0 0 0 0 0 0 0 0 0 0 if ( X i  == Y j  ) c[i,j] = c[i-1,j-1] + 1 else c[i,j] = max( c[i-1,j], c[i,j-1] ) 1 0 0 0 1 1 2 1 1 1 1 1 2 AB C B BD C AB
LCS Example (12) j  0  1  2  3  4  5  0 1 2 3 4 i Xi A B C B Yj B B A C D 0 0 0 0 0 0 0 0 0 0 if ( X i  == Y j  ) c[i,j] = c[i-1,j-1] + 1 else c[i,j] = max( c[i-1,j], c[i,j-1] ) 1 0 0 0 1 1 2 1 1 1 1 2 1 2 2 AB C B BDC AB
LCS Example (13) j  0  1   2  3  4  5  0 1 2 3 4 i Xi A B C B Yj B B A C D 0 0 0 0 0 0 0 0 0 0 if ( X i  == Y j  ) c[i,j] = c[i-1,j-1] + 1 else c[i,j] = max( c[i-1,j], c[i,j-1] ) 1 0 0 0 1 1 2 1 1 1 1 2 1 2 2 1 ABC B B DCAB
LCS Example (14) j  0  1  2  3   4   5  0 1 2 3 4 i Xi A B C B Yj B B A C D 0 0 0 0 0 0 0 0 0 0 if ( X i  == Y j  ) c[i,j] = c[i-1,j-1] + 1 else c[i,j] = max( c[i-1,j], c[i,j-1] ) 1 0 0 0 1 1 2 1 1 1 1 2 1 2 2 1 1 2 2 ABC B B DCA B
LCS Example (15) j  0  1  2  3  4  5   0 1 2 3 4 i Xi A B C B Yj B B A C D 0 0 0 0 0 0 0 0 0 0 if ( X i  == Y j  ) c[i,j] = c[i-1,j-1] + 1 else c[i,j] = max( c[i-1,j], c[i,j-1] ) 1 0 0 0 1 1 2 1 1 1 1 2 1 2 2 1 1 2 2 3 ABC B BDCA B
LCS Algorithm Running Time ,[object Object],[object Object],O(m*n) since each c[i,j] is calculated in constant time, and there are m*n elements in the array
How to find actual LCS ,[object Object],[object Object],[object Object],[object Object],[object Object],2 2 3 2 For example, here  c[i,j] = c[i-1,j-1] +1 = 2+1=3
How to find actual LCS - continued ,[object Object],[object Object],[object Object],[object Object]
Finding LCS j  0  1  2  3  4  5  0 1 2 3 4 i Xi A B C Yj B B A C D 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 1 2 1 1 1 1 2 1 2 2 1 1 2 2 3 B
Finding LCS (2) j  0  1  2  3  4  5  0 1 2 3 4 i Xi A B C Yj B B A C D 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 1 2 1 1 1 1 2 1 2 2 1 1 2 2 3 B B C B LCS (reversed order): LCS (straight order): B  C  B   (this string turned out to be a palindrome)
Knapsack problem ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Knapsack problem There are two versions of the problem: (1) “0-1 knapsack problem” and (2) “Fractional knapsack problem” (1) Items are indivisible; you either take an item or not. Solved with  dynamic programming (2) Items are divisible: you can take any fraction  of an item. Solved with a  greedy algorithm .

More Related Content

What's hot

Mychurch File Upload
Mychurch File UploadMychurch File Upload
Mychurch File Upload
Joe Suh
 
Dynamic programming
Dynamic programmingDynamic programming
Dynamic programming
Shakil Ahmed
 
Solovay Kitaev theorem
Solovay Kitaev theoremSolovay Kitaev theorem
Solovay Kitaev theorem
JamesMa54
 
Solving the energy problem of helium final report
Solving the energy problem of helium final reportSolving the energy problem of helium final report
Solving the energy problem of helium final report
JamesMa54
 
Fast and efficient exact synthesis of single qubit unitaries generated by cli...
Fast and efficient exact synthesis of single qubit unitaries generated by cli...Fast and efficient exact synthesis of single qubit unitaries generated by cli...
Fast and efficient exact synthesis of single qubit unitaries generated by cli...
JamesMa54
 
IIT Jam math 2016 solutions BY Trajectoryeducation
IIT Jam math 2016 solutions BY TrajectoryeducationIIT Jam math 2016 solutions BY Trajectoryeducation
IIT Jam math 2016 solutions BY Trajectoryeducation
Dev Singh
 
Iit jam 2016 physics solutions BY Trajectoryeducation
Iit jam 2016 physics solutions BY TrajectoryeducationIit jam 2016 physics solutions BY Trajectoryeducation
Iit jam 2016 physics solutions BY Trajectoryeducation
Dev Singh
 
Integration SPM
Integration SPMIntegration SPM
Integration SPM
Hanini Hamsan
 
Improper integral
Improper integralImproper integral
Hideitsu Hino
Hideitsu HinoHideitsu Hino
Hideitsu Hino
Suurist
 
Tetsunao Matsuta
Tetsunao MatsutaTetsunao Matsuta
Tetsunao Matsuta
Suurist
 
Multiple Choice Questions_Successive Differentiation (CALCULUS)
Multiple Choice Questions_Successive Differentiation (CALCULUS)Multiple Choice Questions_Successive Differentiation (CALCULUS)
Multiple Choice Questions_Successive Differentiation (CALCULUS)
sanjay gupta
 
Complex analysis notes
Complex analysis notesComplex analysis notes
Complex analysis notes
Prakash Dabhi
 
Recurrence
RecurrenceRecurrence
Engineering Mathematics-IV_B.Tech_Semester-IV_Unit-II
Engineering Mathematics-IV_B.Tech_Semester-IV_Unit-IIEngineering Mathematics-IV_B.Tech_Semester-IV_Unit-II
Engineering Mathematics-IV_B.Tech_Semester-IV_Unit-II
Rai University
 
Pc30 June 2001 Exam Ans Key
Pc30 June 2001 Exam Ans KeyPc30 June 2001 Exam Ans Key
Pc30 June 2001 Exam Ans Key
ingroy
 
E content on algebra & trignomentry
E content on algebra & trignomentryE content on algebra & trignomentry
E content on algebra & trignomentry
V.M. Raut Shri Shivaji Science College, Amravati
 
Hiroyuki Sato
Hiroyuki SatoHiroyuki Sato
Hiroyuki Sato
Suurist
 

What's hot (18)

Mychurch File Upload
Mychurch File UploadMychurch File Upload
Mychurch File Upload
 
Dynamic programming
Dynamic programmingDynamic programming
Dynamic programming
 
Solovay Kitaev theorem
Solovay Kitaev theoremSolovay Kitaev theorem
Solovay Kitaev theorem
 
Solving the energy problem of helium final report
Solving the energy problem of helium final reportSolving the energy problem of helium final report
Solving the energy problem of helium final report
 
Fast and efficient exact synthesis of single qubit unitaries generated by cli...
Fast and efficient exact synthesis of single qubit unitaries generated by cli...Fast and efficient exact synthesis of single qubit unitaries generated by cli...
Fast and efficient exact synthesis of single qubit unitaries generated by cli...
 
IIT Jam math 2016 solutions BY Trajectoryeducation
IIT Jam math 2016 solutions BY TrajectoryeducationIIT Jam math 2016 solutions BY Trajectoryeducation
IIT Jam math 2016 solutions BY Trajectoryeducation
 
Iit jam 2016 physics solutions BY Trajectoryeducation
Iit jam 2016 physics solutions BY TrajectoryeducationIit jam 2016 physics solutions BY Trajectoryeducation
Iit jam 2016 physics solutions BY Trajectoryeducation
 
Integration SPM
Integration SPMIntegration SPM
Integration SPM
 
Improper integral
Improper integralImproper integral
Improper integral
 
Hideitsu Hino
Hideitsu HinoHideitsu Hino
Hideitsu Hino
 
Tetsunao Matsuta
Tetsunao MatsutaTetsunao Matsuta
Tetsunao Matsuta
 
Multiple Choice Questions_Successive Differentiation (CALCULUS)
Multiple Choice Questions_Successive Differentiation (CALCULUS)Multiple Choice Questions_Successive Differentiation (CALCULUS)
Multiple Choice Questions_Successive Differentiation (CALCULUS)
 
Complex analysis notes
Complex analysis notesComplex analysis notes
Complex analysis notes
 
Recurrence
RecurrenceRecurrence
Recurrence
 
Engineering Mathematics-IV_B.Tech_Semester-IV_Unit-II
Engineering Mathematics-IV_B.Tech_Semester-IV_Unit-IIEngineering Mathematics-IV_B.Tech_Semester-IV_Unit-II
Engineering Mathematics-IV_B.Tech_Semester-IV_Unit-II
 
Pc30 June 2001 Exam Ans Key
Pc30 June 2001 Exam Ans KeyPc30 June 2001 Exam Ans Key
Pc30 June 2001 Exam Ans Key
 
E content on algebra & trignomentry
E content on algebra & trignomentryE content on algebra & trignomentry
E content on algebra & trignomentry
 
Hiroyuki Sato
Hiroyuki SatoHiroyuki Sato
Hiroyuki Sato
 

Viewers also liked

Longest Common Subsequence (LCS) Algorithm
Longest Common Subsequence (LCS) AlgorithmLongest Common Subsequence (LCS) Algorithm
Longest Common Subsequence (LCS) Algorithm
Darshit Metaliya
 
Knapsack Problem
Knapsack ProblemKnapsack Problem
Knapsack Problem
Jenny Galino
 
Longest Common Subsequence
Longest Common SubsequenceLongest Common Subsequence
Longest Common Subsequence
Krishma Parekh
 
Skiena algorithm 2007 lecture16 introduction to dynamic programming
Skiena algorithm 2007 lecture16 introduction to dynamic programmingSkiena algorithm 2007 lecture16 introduction to dynamic programming
Skiena algorithm 2007 lecture16 introduction to dynamic programming
zukun
 
Pascal’s triangle
Pascal’s trianglePascal’s triangle
Pascal’s triangle
Tarun Gehlot
 
Pascal's Triangle
Pascal's TrianglePascal's Triangle
Pascal's Triangle
MehmetErolu1
 
Pascal Triangle
Pascal TrianglePascal Triangle
Pascal Triangle
Joseph Nilo
 
Pascal's triangle [compatibility mode]
Pascal's triangle [compatibility mode]Pascal's triangle [compatibility mode]
Pascal's triangle [compatibility mode]
Adarshtiwari2000
 
Pascal's Triangle
Pascal's TrianglePascal's Triangle
Pascal's Triangle
vbhunt
 
Visualizing the pascal’s triangle
Visualizing the pascal’s triangleVisualizing the pascal’s triangle
Visualizing the pascal’s triangle
Parth Dhar
 
Pascal's triangle
Pascal's triangle Pascal's triangle
Pascal's triangle
arnav1230
 
Pascal Triangle
Pascal TrianglePascal Triangle
Pascal Triangle
nur fara
 
Pascal’s Triangle
Pascal’s TrianglePascal’s Triangle
Pascal’s Triangle
Clayton Rainsberg
 
Pascal's triangle Maths Investigation
Pascal's triangle Maths InvestigationPascal's triangle Maths Investigation
Pascal's triangle Maths Investigation
Jacqueline Harmer
 
Rabin Karp - String Matching Algorithm
Rabin Karp - String Matching AlgorithmRabin Karp - String Matching Algorithm
Rabin Karp - String Matching Algorithm
Syed Owais Ali Chishti
 
Triangles
TrianglesTriangles
Triangles
karniksingh
 
LCS Problem
LCS ProblemLCS Problem
LCS Problem
Hoang Nguyen
 
The Archaeology Of Mayan Civilization
The Archaeology Of Mayan CivilizationThe Archaeology Of Mayan Civilization
The Archaeology Of Mayan Civilization
Faiza Rehman
 
Rabin karp string matching algorithm
Rabin karp string matching algorithmRabin karp string matching algorithm
Rabin karp string matching algorithm
Gajanand Sharma
 
Greedy method class 11
Greedy method class 11Greedy method class 11
Greedy method class 11
Kumar
 

Viewers also liked (20)

Longest Common Subsequence (LCS) Algorithm
Longest Common Subsequence (LCS) AlgorithmLongest Common Subsequence (LCS) Algorithm
Longest Common Subsequence (LCS) Algorithm
 
Knapsack Problem
Knapsack ProblemKnapsack Problem
Knapsack Problem
 
Longest Common Subsequence
Longest Common SubsequenceLongest Common Subsequence
Longest Common Subsequence
 
Skiena algorithm 2007 lecture16 introduction to dynamic programming
Skiena algorithm 2007 lecture16 introduction to dynamic programmingSkiena algorithm 2007 lecture16 introduction to dynamic programming
Skiena algorithm 2007 lecture16 introduction to dynamic programming
 
Pascal’s triangle
Pascal’s trianglePascal’s triangle
Pascal’s triangle
 
Pascal's Triangle
Pascal's TrianglePascal's Triangle
Pascal's Triangle
 
Pascal Triangle
Pascal TrianglePascal Triangle
Pascal Triangle
 
Pascal's triangle [compatibility mode]
Pascal's triangle [compatibility mode]Pascal's triangle [compatibility mode]
Pascal's triangle [compatibility mode]
 
Pascal's Triangle
Pascal's TrianglePascal's Triangle
Pascal's Triangle
 
Visualizing the pascal’s triangle
Visualizing the pascal’s triangleVisualizing the pascal’s triangle
Visualizing the pascal’s triangle
 
Pascal's triangle
Pascal's triangle Pascal's triangle
Pascal's triangle
 
Pascal Triangle
Pascal TrianglePascal Triangle
Pascal Triangle
 
Pascal’s Triangle
Pascal’s TrianglePascal’s Triangle
Pascal’s Triangle
 
Pascal's triangle Maths Investigation
Pascal's triangle Maths InvestigationPascal's triangle Maths Investigation
Pascal's triangle Maths Investigation
 
Rabin Karp - String Matching Algorithm
Rabin Karp - String Matching AlgorithmRabin Karp - String Matching Algorithm
Rabin Karp - String Matching Algorithm
 
Triangles
TrianglesTriangles
Triangles
 
LCS Problem
LCS ProblemLCS Problem
LCS Problem
 
The Archaeology Of Mayan Civilization
The Archaeology Of Mayan CivilizationThe Archaeology Of Mayan Civilization
The Archaeology Of Mayan Civilization
 
Rabin karp string matching algorithm
Rabin karp string matching algorithmRabin karp string matching algorithm
Rabin karp string matching algorithm
 
Greedy method class 11
Greedy method class 11Greedy method class 11
Greedy method class 11
 

Similar to lecture 24

Dynamic1
Dynamic1Dynamic1
Dynamic1
MyAlome
 
Dynamic Programing_LCS.ppt
Dynamic Programing_LCS.pptDynamic Programing_LCS.ppt
Dynamic Programing_LCS.ppt
manasgaming4
 
Longest common subsequence(dynamic programming).
Longest common subsequence(dynamic programming).Longest common subsequence(dynamic programming).
Longest common subsequence(dynamic programming).
munawerzareef
 
Free video lectures for mca
Free video lectures for mcaFree video lectures for mca
Free video lectures for mca
Edhole.com
 
4th Semester (Dec-2015; Jan-2016) Civil Engineering Question Paper
4th Semester (Dec-2015; Jan-2016) Civil Engineering Question Paper4th Semester (Dec-2015; Jan-2016) Civil Engineering Question Paper
4th Semester (Dec-2015; Jan-2016) Civil Engineering Question Paper
BGS Institute of Technology, Adichunchanagiri University (ACU)
 
Longest common subsequence
Longest common subsequenceLongest common subsequence
Longest common subsequence
Kiran K
 
17-dynprog2.ppt
17-dynprog2.ppt17-dynprog2.ppt
17-dynprog2.ppt
GGHSJANDAWALA
 
17-dynprog2 17-dynprog2 17-dynprog2 17-dynprog2
17-dynprog2 17-dynprog2 17-dynprog2 17-dynprog217-dynprog2 17-dynprog2 17-dynprog2 17-dynprog2
17-dynprog2 17-dynprog2 17-dynprog2 17-dynprog2
Shanmuganathan C
 
Numerical Methods Solving Linear Equations
Numerical Methods Solving Linear EquationsNumerical Methods Solving Linear Equations
Solucao_Marion_Thornton_Dinamica_Classic (1).pdf
Solucao_Marion_Thornton_Dinamica_Classic (1).pdfSolucao_Marion_Thornton_Dinamica_Classic (1).pdf
Solucao_Marion_Thornton_Dinamica_Classic (1).pdf
FranciscoJavierCaedo
 
Solutions manual for logic and computer design fundamentals 5th edition by ma...
Solutions manual for logic and computer design fundamentals 5th edition by ma...Solutions manual for logic and computer design fundamentals 5th edition by ma...
Solutions manual for logic and computer design fundamentals 5th edition by ma...
Beckham000
 
A fixed point theorem for weakly c contraction mappings of integral type.
A fixed point theorem for  weakly c   contraction mappings of integral type.A fixed point theorem for  weakly c   contraction mappings of integral type.
A fixed point theorem for weakly c contraction mappings of integral type.
Alexander Decker
 
4th Semester (July-2016) Civil Engineering Question Paper
4th Semester (July-2016) Civil Engineering Question Paper4th Semester (July-2016) Civil Engineering Question Paper
4th Semester (July-2016) Civil Engineering Question Paper
BGS Institute of Technology, Adichunchanagiri University (ACU)
 
Heuristic Algorithm for Finding Sensitivity Analysis in Interval Solid Transp...
Heuristic Algorithm for Finding Sensitivity Analysis in Interval Solid Transp...Heuristic Algorithm for Finding Sensitivity Analysis in Interval Solid Transp...
Heuristic Algorithm for Finding Sensitivity Analysis in Interval Solid Transp...
AM Publications
 
4th Semester Civil Engineering (2013-December) Question Papers
4th Semester Civil Engineering (2013-December) Question Papers4th Semester Civil Engineering (2013-December) Question Papers
4th Semester Civil Engineering (2013-December) Question Papers
BGS Institute of Technology, Adichunchanagiri University (ACU)
 
ISI MSQE Entrance Question Paper (2010)
ISI MSQE Entrance Question Paper (2010)ISI MSQE Entrance Question Paper (2010)
ISI MSQE Entrance Question Paper (2010)
CrackDSE
 
jacobi method, gauss siedel for solving linear equations
jacobi method, gauss siedel for solving linear equationsjacobi method, gauss siedel for solving linear equations
jacobi method, gauss siedel for solving linear equations
Department of Telecommunications, Ministry of Communication & IT (INDIA)
 
3rd Semester Mechanical Engineering (June/July-2015) Question Papers
3rd Semester Mechanical Engineering  (June/July-2015) Question Papers3rd Semester Mechanical Engineering  (June/July-2015) Question Papers
3rd Semester Mechanical Engineering (June/July-2015) Question Papers
BGS Institute of Technology, Adichunchanagiri University (ACU)
 
Boolean algebra And Logic Gates
Boolean algebra And Logic GatesBoolean algebra And Logic Gates
Boolean algebra And Logic Gates
Kumar
 
Lecture 4 (27)
Lecture 4 (27)Lecture 4 (27)
Lecture 4 (27)
Basel Samhouri
 

Similar to lecture 24 (20)

Dynamic1
Dynamic1Dynamic1
Dynamic1
 
Dynamic Programing_LCS.ppt
Dynamic Programing_LCS.pptDynamic Programing_LCS.ppt
Dynamic Programing_LCS.ppt
 
Longest common subsequence(dynamic programming).
Longest common subsequence(dynamic programming).Longest common subsequence(dynamic programming).
Longest common subsequence(dynamic programming).
 
Free video lectures for mca
Free video lectures for mcaFree video lectures for mca
Free video lectures for mca
 
4th Semester (Dec-2015; Jan-2016) Civil Engineering Question Paper
4th Semester (Dec-2015; Jan-2016) Civil Engineering Question Paper4th Semester (Dec-2015; Jan-2016) Civil Engineering Question Paper
4th Semester (Dec-2015; Jan-2016) Civil Engineering Question Paper
 
Longest common subsequence
Longest common subsequenceLongest common subsequence
Longest common subsequence
 
17-dynprog2.ppt
17-dynprog2.ppt17-dynprog2.ppt
17-dynprog2.ppt
 
17-dynprog2 17-dynprog2 17-dynprog2 17-dynprog2
17-dynprog2 17-dynprog2 17-dynprog2 17-dynprog217-dynprog2 17-dynprog2 17-dynprog2 17-dynprog2
17-dynprog2 17-dynprog2 17-dynprog2 17-dynprog2
 
Numerical Methods Solving Linear Equations
Numerical Methods Solving Linear EquationsNumerical Methods Solving Linear Equations
Numerical Methods Solving Linear Equations
 
Solucao_Marion_Thornton_Dinamica_Classic (1).pdf
Solucao_Marion_Thornton_Dinamica_Classic (1).pdfSolucao_Marion_Thornton_Dinamica_Classic (1).pdf
Solucao_Marion_Thornton_Dinamica_Classic (1).pdf
 
Solutions manual for logic and computer design fundamentals 5th edition by ma...
Solutions manual for logic and computer design fundamentals 5th edition by ma...Solutions manual for logic and computer design fundamentals 5th edition by ma...
Solutions manual for logic and computer design fundamentals 5th edition by ma...
 
A fixed point theorem for weakly c contraction mappings of integral type.
A fixed point theorem for  weakly c   contraction mappings of integral type.A fixed point theorem for  weakly c   contraction mappings of integral type.
A fixed point theorem for weakly c contraction mappings of integral type.
 
4th Semester (July-2016) Civil Engineering Question Paper
4th Semester (July-2016) Civil Engineering Question Paper4th Semester (July-2016) Civil Engineering Question Paper
4th Semester (July-2016) Civil Engineering Question Paper
 
Heuristic Algorithm for Finding Sensitivity Analysis in Interval Solid Transp...
Heuristic Algorithm for Finding Sensitivity Analysis in Interval Solid Transp...Heuristic Algorithm for Finding Sensitivity Analysis in Interval Solid Transp...
Heuristic Algorithm for Finding Sensitivity Analysis in Interval Solid Transp...
 
4th Semester Civil Engineering (2013-December) Question Papers
4th Semester Civil Engineering (2013-December) Question Papers4th Semester Civil Engineering (2013-December) Question Papers
4th Semester Civil Engineering (2013-December) Question Papers
 
ISI MSQE Entrance Question Paper (2010)
ISI MSQE Entrance Question Paper (2010)ISI MSQE Entrance Question Paper (2010)
ISI MSQE Entrance Question Paper (2010)
 
jacobi method, gauss siedel for solving linear equations
jacobi method, gauss siedel for solving linear equationsjacobi method, gauss siedel for solving linear equations
jacobi method, gauss siedel for solving linear equations
 
3rd Semester Mechanical Engineering (June/July-2015) Question Papers
3rd Semester Mechanical Engineering  (June/July-2015) Question Papers3rd Semester Mechanical Engineering  (June/July-2015) Question Papers
3rd Semester Mechanical Engineering (June/July-2015) Question Papers
 
Boolean algebra And Logic Gates
Boolean algebra And Logic GatesBoolean algebra And Logic Gates
Boolean algebra And Logic Gates
 
Lecture 4 (27)
Lecture 4 (27)Lecture 4 (27)
Lecture 4 (27)
 

More from sajinsc

lecture 30
lecture 30lecture 30
lecture 30
sajinsc
 
lecture 29
lecture 29lecture 29
lecture 29
sajinsc
 
lecture 28
lecture 28lecture 28
lecture 28
sajinsc
 
lecture 27
lecture 27lecture 27
lecture 27
sajinsc
 
lecture 26
lecture 26lecture 26
lecture 26
sajinsc
 
lecture 25
lecture 25lecture 25
lecture 25
sajinsc
 
lecture 22
lecture 22lecture 22
lecture 22
sajinsc
 
lecture 21
lecture 21lecture 21
lecture 21
sajinsc
 
lecture 20
lecture 20lecture 20
lecture 20
sajinsc
 
lecture 19
lecture 19lecture 19
lecture 19
sajinsc
 
lecture 18
lecture 18lecture 18
lecture 18
sajinsc
 
lecture 17
lecture 17lecture 17
lecture 17
sajinsc
 
lecture 16
lecture 16lecture 16
lecture 16
sajinsc
 
lecture 15
lecture 15lecture 15
lecture 15
sajinsc
 
lecture 14
lecture 14lecture 14
lecture 14
sajinsc
 
lecture 13
lecture 13lecture 13
lecture 13
sajinsc
 
lecture 12
lecture 12lecture 12
lecture 12
sajinsc
 
lecture 11
lecture 11lecture 11
lecture 11
sajinsc
 
lecture 10
lecture 10lecture 10
lecture 10
sajinsc
 
lecture 9
lecture 9lecture 9
lecture 9
sajinsc
 

More from sajinsc (20)

lecture 30
lecture 30lecture 30
lecture 30
 
lecture 29
lecture 29lecture 29
lecture 29
 
lecture 28
lecture 28lecture 28
lecture 28
 
lecture 27
lecture 27lecture 27
lecture 27
 
lecture 26
lecture 26lecture 26
lecture 26
 
lecture 25
lecture 25lecture 25
lecture 25
 
lecture 22
lecture 22lecture 22
lecture 22
 
lecture 21
lecture 21lecture 21
lecture 21
 
lecture 20
lecture 20lecture 20
lecture 20
 
lecture 19
lecture 19lecture 19
lecture 19
 
lecture 18
lecture 18lecture 18
lecture 18
 
lecture 17
lecture 17lecture 17
lecture 17
 
lecture 16
lecture 16lecture 16
lecture 16
 
lecture 15
lecture 15lecture 15
lecture 15
 
lecture 14
lecture 14lecture 14
lecture 14
 
lecture 13
lecture 13lecture 13
lecture 13
 
lecture 12
lecture 12lecture 12
lecture 12
 
lecture 11
lecture 11lecture 11
lecture 11
 
lecture 10
lecture 10lecture 10
lecture 10
 
lecture 9
lecture 9lecture 9
lecture 9
 

Recently uploaded

PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
Dr. Shivangi Singh Parihar
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
AyyanKhan40
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
Dr. Mulla Adam Ali
 
BBR 2024 Summer Sessions Interview Training
BBR  2024 Summer Sessions Interview TrainingBBR  2024 Summer Sessions Interview Training
BBR 2024 Summer Sessions Interview Training
Katrina Pritchard
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
David Douglas School District
 
Cognitive Development Adolescence Psychology
Cognitive Development Adolescence PsychologyCognitive Development Adolescence Psychology
Cognitive Development Adolescence Psychology
paigestewart1632
 
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
GeorgeMilliken2
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
Priyankaranawat4
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
Priyankaranawat4
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
Israel Genealogy Research Association
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
PECB
 
Main Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docxMain Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docx
adhitya5119
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
tarandeep35
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
Colégio Santa Teresinha
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Akanksha trivedi rama nursing college kanpur.
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
TechSoup
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
WaniBasim
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
Academy of Science of South Africa
 
How to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRMHow to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRM
Celine George
 
How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17
Celine George
 

Recently uploaded (20)

PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
 
BBR 2024 Summer Sessions Interview Training
BBR  2024 Summer Sessions Interview TrainingBBR  2024 Summer Sessions Interview Training
BBR 2024 Summer Sessions Interview Training
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
 
Cognitive Development Adolescence Psychology
Cognitive Development Adolescence PsychologyCognitive Development Adolescence Psychology
Cognitive Development Adolescence Psychology
 
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
 
Main Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docxMain Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docx
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
 
How to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRMHow to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRM
 
How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17
 

lecture 24

  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11. LCS Example (0) j 0 1 2 3 4 5 0 1 2 3 4 i Xi A B C B Yj B B A C D X = ABCB; m = |X| = 4 Y = BDCAB; n = |Y| = 5 Allocate array c[5,4] ABCB BDCAB
  • 12. LCS Example (1) j 0 1 2 3 4 5 0 1 2 3 4 i Xi A B C B Yj B B A C D 0 0 0 0 0 0 0 0 0 0 for i = 1 to m c[i,0] = 0 for j = 1 to n c[0,j] = 0 ABCB BDCAB
  • 13. LCS Example (2) j 0 1 2 3 4 5 0 1 2 3 4 i Xi A B C B Yj B B A C D 0 0 0 0 0 0 0 0 0 0 if ( X i == Y j ) c[i,j] = c[i-1,j-1] + 1 else c[i,j] = max( c[i-1,j], c[i,j-1] ) 0 A BCB B DCAB
  • 14. LCS Example (3) j 0 1 2 3 4 5 0 1 2 3 4 i Xi A B C B Yj B B A C D 0 0 0 0 0 0 0 0 0 0 if ( X i == Y j ) c[i,j] = c[i-1,j-1] + 1 else c[i,j] = max( c[i-1,j], c[i,j-1] ) 0 0 0 A BCB B DC AB
  • 15. LCS Example (4) j 0 1 2 3 4 5 0 1 2 3 4 i Xi A B C B Yj B B A C D 0 0 0 0 0 0 0 0 0 0 if ( X i == Y j ) c[i,j] = c[i-1,j-1] + 1 else c[i,j] = max( c[i-1,j], c[i,j-1] ) 0 0 0 1 A BCB BDC A B
  • 16. LCS Example (5) j 0 1 2 3 4 5 0 1 2 3 4 i Xi A B C B Yj B B A C D 0 0 0 0 0 0 0 0 0 0 if ( X i == Y j ) c[i,j] = c[i-1,j-1] + 1 else c[i,j] = max( c[i-1,j], c[i,j-1] ) 0 0 0 1 1 A BCB BDCA B
  • 17. LCS Example (6) j 0 1 2 3 4 5 0 1 2 3 4 i Xi A B C B Yj B B A C D 0 0 0 0 0 0 0 0 0 0 if ( X i == Y j ) c[i,j] = c[i-1,j-1] + 1 else c[i,j] = max( c[i-1,j], c[i,j-1] ) 0 0 1 0 1 1 A B CB B DCAB
  • 18. LCS Example (7) j 0 1 2 3 4 5 0 1 2 3 4 i Xi A B C B Yj B B A C D 0 0 0 0 0 0 0 0 0 0 if ( X i == Y j ) c[i,j] = c[i-1,j-1] + 1 else c[i,j] = max( c[i-1,j], c[i,j-1] ) 1 0 0 0 1 1 1 1 1 A B CB B DCA B
  • 19. LCS Example (8) j 0 1 2 3 4 5 0 1 2 3 4 i Xi A B C B Yj B B A C D 0 0 0 0 0 0 0 0 0 0 if ( X i == Y j ) c[i,j] = c[i-1,j-1] + 1 else c[i,j] = max( c[i-1,j], c[i,j-1] ) 1 0 0 0 1 1 1 1 1 2 A B CB BDCA B
  • 20. LCS Example (10) j 0 1 2 3 4 5 0 1 2 3 4 i Xi A B C B Yj B B A C D 0 0 0 0 0 0 0 0 0 0 if ( X i == Y j ) c[i,j] = c[i-1,j-1] + 1 else c[i,j] = max( c[i-1,j], c[i,j-1] ) 1 0 0 0 1 2 1 1 1 1 1 1 AB C B BD CAB
  • 21. LCS Example (11) j 0 1 2 3 4 5 0 1 2 3 4 i Xi A B C B Yj B B A C D 0 0 0 0 0 0 0 0 0 0 if ( X i == Y j ) c[i,j] = c[i-1,j-1] + 1 else c[i,j] = max( c[i-1,j], c[i,j-1] ) 1 0 0 0 1 1 2 1 1 1 1 1 2 AB C B BD C AB
  • 22. LCS Example (12) j 0 1 2 3 4 5 0 1 2 3 4 i Xi A B C B Yj B B A C D 0 0 0 0 0 0 0 0 0 0 if ( X i == Y j ) c[i,j] = c[i-1,j-1] + 1 else c[i,j] = max( c[i-1,j], c[i,j-1] ) 1 0 0 0 1 1 2 1 1 1 1 2 1 2 2 AB C B BDC AB
  • 23. LCS Example (13) j 0 1 2 3 4 5 0 1 2 3 4 i Xi A B C B Yj B B A C D 0 0 0 0 0 0 0 0 0 0 if ( X i == Y j ) c[i,j] = c[i-1,j-1] + 1 else c[i,j] = max( c[i-1,j], c[i,j-1] ) 1 0 0 0 1 1 2 1 1 1 1 2 1 2 2 1 ABC B B DCAB
  • 24. LCS Example (14) j 0 1 2 3 4 5 0 1 2 3 4 i Xi A B C B Yj B B A C D 0 0 0 0 0 0 0 0 0 0 if ( X i == Y j ) c[i,j] = c[i-1,j-1] + 1 else c[i,j] = max( c[i-1,j], c[i,j-1] ) 1 0 0 0 1 1 2 1 1 1 1 2 1 2 2 1 1 2 2 ABC B B DCA B
  • 25. LCS Example (15) j 0 1 2 3 4 5 0 1 2 3 4 i Xi A B C B Yj B B A C D 0 0 0 0 0 0 0 0 0 0 if ( X i == Y j ) c[i,j] = c[i-1,j-1] + 1 else c[i,j] = max( c[i-1,j], c[i,j-1] ) 1 0 0 0 1 1 2 1 1 1 1 2 1 2 2 1 1 2 2 3 ABC B BDCA B
  • 26.
  • 27.
  • 28.
  • 29. Finding LCS j 0 1 2 3 4 5 0 1 2 3 4 i Xi A B C Yj B B A C D 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 1 2 1 1 1 1 2 1 2 2 1 1 2 2 3 B
  • 30. Finding LCS (2) j 0 1 2 3 4 5 0 1 2 3 4 i Xi A B C Yj B B A C D 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 1 2 1 1 1 1 2 1 2 2 1 1 2 2 3 B B C B LCS (reversed order): LCS (straight order): B C B (this string turned out to be a palindrome)
  • 31.
  • 32. Knapsack problem There are two versions of the problem: (1) “0-1 knapsack problem” and (2) “Fractional knapsack problem” (1) Items are indivisible; you either take an item or not. Solved with dynamic programming (2) Items are divisible: you can take any fraction of an item. Solved with a greedy algorithm .