SlideShare une entreprise Scribd logo
1  sur  32
[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 .

Contenu connexe

Tendances

Mychurch File Upload
Mychurch File UploadMychurch File Upload
Mychurch File UploadJoe Suh
 
Dynamic programming
Dynamic programmingDynamic programming
Dynamic programmingShakil Ahmed
 
Solovay Kitaev theorem
Solovay Kitaev theoremSolovay Kitaev theorem
Solovay Kitaev theoremJamesMa54
 
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 reportJamesMa54
 
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 TrajectoryeducationDev 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 TrajectoryeducationDev Singh
 
Hideitsu Hino
Hideitsu HinoHideitsu Hino
Hideitsu HinoSuurist
 
Tetsunao Matsuta
Tetsunao MatsutaTetsunao Matsuta
Tetsunao MatsutaSuurist
 
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 notesPrakash Dabhi
 
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-IIRai University
 
Pc30 June 2001 Exam Ans Key
Pc30 June 2001 Exam Ans KeyPc30 June 2001 Exam Ans Key
Pc30 June 2001 Exam Ans Keyingroy
 
Hiroyuki Sato
Hiroyuki SatoHiroyuki Sato
Hiroyuki SatoSuurist
 

Tendances (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
 

En vedette

Longest Common Subsequence (LCS) Algorithm
Longest Common Subsequence (LCS) AlgorithmLongest Common Subsequence (LCS) Algorithm
Longest Common Subsequence (LCS) AlgorithmDarshit Metaliya
 
Longest Common Subsequence
Longest Common SubsequenceLongest Common Subsequence
Longest Common SubsequenceKrishma 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 programmingzukun
 
Pascal’s triangle
Pascal’s trianglePascal’s triangle
Pascal’s triangleTarun Gehlot
 
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 Trianglevbhunt
 
Visualizing the pascal’s triangle
Visualizing the pascal’s triangleVisualizing the pascal’s triangle
Visualizing the pascal’s triangleParth Dhar
 
Pascal's triangle
Pascal's triangle Pascal's triangle
Pascal's triangle arnav1230
 
Pascal Triangle
Pascal TrianglePascal Triangle
Pascal Trianglenur fara
 
Pascal's triangle Maths Investigation
Pascal's triangle Maths InvestigationPascal's triangle Maths Investigation
Pascal's triangle Maths InvestigationJacqueline Harmer
 
Rabin Karp - String Matching Algorithm
Rabin Karp - String Matching AlgorithmRabin Karp - String Matching Algorithm
Rabin Karp - String Matching AlgorithmSyed Owais Ali Chishti
 
The Archaeology Of Mayan Civilization
The Archaeology Of Mayan CivilizationThe Archaeology Of Mayan Civilization
The Archaeology Of Mayan CivilizationFaiza Rehman
 
Rabin karp string matching algorithm
Rabin karp string matching algorithmRabin karp string matching algorithm
Rabin karp string matching algorithmGajanand Sharma
 
Greedy method class 11
Greedy method class 11Greedy method class 11
Greedy method class 11Kumar
 

En vedette (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
 

Similaire à lecture 24

Dynamic1
Dynamic1Dynamic1
Dynamic1MyAlome
 
Dynamic Programing_LCS.ppt
Dynamic Programing_LCS.pptDynamic Programing_LCS.ppt
Dynamic Programing_LCS.pptmanasgaming4
 
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 mcaEdhole.com
 
Longest common subsequence
Longest common subsequenceLongest common subsequence
Longest common subsequenceKiran K
 
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-dynprog2Shanmuganathan C
 
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).pdfFranciscoJavierCaedo
 
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
 
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
 
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
 
Boolean algebra And Logic Gates
Boolean algebra And Logic GatesBoolean algebra And Logic Gates
Boolean algebra And Logic GatesKumar
 

Similaire à 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)
 

Plus de sajinsc

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

Plus de 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
 

Dernier

Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxnegromaestrong
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
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
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfChris Hunter
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfSanaAli374401
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Shubhangi Sonawane
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docxPoojaSen20
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingTeacherCyreneCayanan
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docxPoojaSen20
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 

Dernier (20)

Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
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.
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdf
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 

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 .