Global alignment in linear space

Similar documents
The solution is often represented as a vector: 2xI + 4X2 + 2X3 + 4X4 + 2X5 = 4 2xI + 4X2 + 3X3 + 3X4 + 3X5 = 4. 3xI + 6X2 + 6X3 + 3X4 + 6X5 = 6.

Linear Quadratic Regulator (LQR) - State Feedback Design

Released Assessment Questions, 2017 QUESTIONS

Math 2142 Exam 1 Review Problems. x 2 + f (0) 3! for the 3rd Taylor polynomial at x = 0. To calculate the various quantities:

e t dt e t dt = lim e t dt T (1 e T ) = 1

ANSWERS TO EVEN NUMBERED EXERCISES IN CHAPTER 2

Chapter 2: Evaluative Feedback

Bipartite Matching. Matching. Bipartite Matching. Maxflow Formulation

Problem Set 9 Due December, 7

Motion. Part 2: Constant Acceleration. Acceleration. October Lab Physics. Ms. Levine 1. Acceleration. Acceleration. Units for Acceleration.

A LOG IS AN EXPONENT.

4.8 Improper Integrals

CSC 373: Algorithm Design and Analysis Lecture 9

P441 Analytical Mechanics - I. Coupled Oscillators. c Alex R. Dzierba

Maximum Flow. Flow Graph

Optimal Transform: The Karhunen-Loeve Transform (KLT)

1. Find a basis for the row space of each of the following matrices. Your basis should consist of rows of the original matrix.

Contraction Mapping Principle Approach to Differential Equations

September 20 Homework Solutions

Review for the Midterm Exam.

AID up-mutants isolated using a high-throughput screen highlight the. immunity/cancer balance limiting DNA deaminase activity

A 1.3 m 2.5 m 2.8 m. x = m m = 8400 m. y = 4900 m 3200 m = 1700 m

PHYSICS 1210 Exam 1 University of Wyoming 14 February points

Physics 2A HW #3 Solutions

rank Additionally system of equation only independent atfect Gawp (A) possible ( Alb ) easily process form rang A. Proposition with Definition

Boyce/DiPrima 9 th ed, Ch 6.1: Definition of. Laplace Transform. In this chapter we use the Laplace transform to convert a

An integral having either an infinite limit of integration or an unbounded integrand is called improper. Here are two examples.

Randomized Perfect Bipartite Matching

ME 391 Mechanical Engineering Analysis

Network Flow. Data Structures and Algorithms Andrei Bulatov

e 2t u(t) e 2t u(t) =?

Lecture 2: Network Flow. c 14

two values, false and true used in mathematical logic, and to two voltage levels, LOW and HIGH used in switching circuits.

18.06 Problem Set 4 Due Wednesday, Oct. 11, 2006 at 4:00 p.m. in 2-106

Position, Velocity, and Acceleration

6.003 Homework #8 Solutions

0 for t < 0 1 for t > 0

Global alignment. Genome Rearrangements Finding preserved genes. Lecture 18

Three Dimensional Coordinate Geometry

t is a basis for the solution space to this system, then the matrix having these solutions as columns, t x 1 t, x 2 t,... x n t x 2 t...

Solutions to assignment 3

f(x) dx with An integral having either an infinite limit of integration or an unbounded integrand is called improper. Here are two examples dx x x 2

Reinforcement Learning

Section 2.3. Matrix Inverses

10. State Space Methods

Some Basic Information about M-S-D Systems

Solutions of Sample Problems for Third In-Class Exam Math 246, Spring 2011, Professor David Levermore

Chapter Direct Method of Interpolation

MTH 146 Class 11 Notes

Tutorial Worksheet. 1. Find all solutions to the linear system by following the given steps. x + 2y + 3z = 2 2x + 3y + z = 4.

Physic 231 Lecture 4. Mi it ftd l t. Main points of today s lecture: Example: addition of velocities Trajectories of objects in 2 = =

Matrix Algebra. Matrix Addition, Scalar Multiplication and Transposition. Linear Algebra I 24

Properties of Logarithms. Solving Exponential and Logarithmic Equations. Properties of Logarithms. Properties of Logarithms. ( x)

Reading from Young & Freedman: For this topic, read sections 25.4 & 25.5, the introduction to chapter 26 and sections 26.1 to 26.2 & 26.4.

dt = C exp (3 ln t 4 ). t 4 W = C exp ( ln(4 t) 3) = C(4 t) 3.

B Signals and Systems I Solutions to Midterm Test 2. xt ()

Computing data with spreadsheets. Enter the following into the corresponding cells: A1: n B1: triangle C1: sqrt

Continuous Time Markov Chain (Markov Process)

Announcements: Warm-up Exercise:

Prefix-Free Regular-Expression Matching

Minimum Squared Error

A1.1.1 Model for the vertical stress comparison between the FLAC ubiquitous joints model and the theoretical development in Jaeger and Cook (1979)

Minimum Squared Error

V L. DT s D T s t. Figure 1: Buck-boost converter: inductor current i(t) in the continuous conduction mode.

the king's singers And So It Goes the colour of song Words and Vusic by By Joel LEONARD Arranged by Bob Chilcott

Designing A Fanlike Structure

Max Flow, Min Cut COS 521. Kevin Wayne Fall Soviet Rail Network, Cuts. Minimum Cut Problem. Flow network.

Product Operators. Fundamentals of MR Alec Ricciuti 3 March 2011

Amit Mehra. Indian School of Business, Hyderabad, INDIA Vijay Mookerjee

ES 250 Practice Final Exam

x i v x t a dx dt t x

Transformations. Ordered set of numbers: (1,2,3,4) Example: (x,y,z) coordinates of pt in space. Vectors

non -negative cone Population dynamics motivates the study of linear models whose coefficient matrices are non-negative or positive.

MATH 31B: MIDTERM 2 REVIEW. x 2 e x2 2x dx = 1. ue u du 2. x 2 e x2 e x2] + C 2. dx = x ln(x) 2 2. ln x dx = x ln x x + C. 2, or dx = 2u du.

Chapter 2. Motion along a straight line. 9/9/2015 Physics 218

Designing Information Devices and Systems I Spring 2019 Lecture Notes Note 17

Solutions to Problems from Chapter 2

Online Appendix for "Customer Recognition in. Experience versus Inspection Good Markets"

CS473 - Algorithms I

(b) 10 yr. (b) 13 m. 1.6 m s, m s m s (c) 13.1 s. 32. (a) 20.0 s (b) No, the minimum distance to stop = 1.00 km. 1.

Math Week 14 April 16-20: sections first order systems of linear differential equations; 7.4 mass-spring systems.

SOLUTIONS TO ECE 3084

Finish reading Chapter 2 of Spivak, rereading earlier sections as necessary. handout and fill in some missing details!

Introduction To Matrices MCV 4UI Assignment #1

MATH 128A, SUMMER 2009, FINAL EXAM SOLUTION

Computer Aided Geometric Design

Biol. 356 Lab 8. Mortality, Recruitment, and Migration Rates

The Procedure Abstraction Part II: Symbol Tables and Activation Records

REAL ANALYSIS I HOMEWORK 3. Chapter 1

SEMANTIC ANALYSIS PRINCIPLES OF PROGRAMMING LANGUAGES. Norbert Zeh Winter Dalhousie University 1/28

ODEs II, Lecture 1: Homogeneous Linear Systems - I. Mike Raugh 1. March 8, 2004

Math 4600: Homework 11 Solutions

A Kalman filtering simulation

Section 1.2 Angles and Angle Measure

How to Prove the Riemann Hypothesis Author: Fayez Fok Al Adeh.

Lecture 1 - Introduction and Basic Facts about PDEs

Idealize Bioreactor CSTR vs. PFR... 3 Analysis of a simple continuous stirred tank bioreactor... 4 Residence time distribution... 4 F curve:...

ENGR 1990 Engineering Mathematics The Integral of a Function as a Function

Math 334 Fall 2011 Homework 11 Solutions

Machine Learning 4771

Transcription:

Globl linmen in liner spe 1

2 Globl linmen in liner spe Gol: Find n opiml linmen of A[1..n] nd B[1..m] in liner spe, i.e. O(n) Exisin lorihm: Globl linmen wih bkrkin O(nm) ime nd spe, bu he opiml os n be found in spe O(n)

3 Globl linmen in liner spe Gol: Find n opiml linmen of A[1..n] nd B[1..m] in liner spe, i.e. O(n) Exisin lorihm: Globl linmen wih bkrkin O(nm) ime nd spe, bu he opiml os n be found in spe O(n)

4 Liner spe Firs ide Firs ide: Keep only wo rows in memory nd reompue when oher prs of he mrix is needed durin bkrkin... nm

5 Liner spe Firs ide Firs ide: Keep only wo rows in memory nd reompue when oher prs of he mrix is needed durin bkrkin... nm

6 Liner spe Firs ide Firs ide: Keep only wo rows in memory nd reompue when oher prs of he mrix is needed durin bkrkin... nm + (n-2)m +

7 Liner spe Firs ide Firs ide: Keep only wo rows in memory nd reompue when oher prs of he mrix is needed durin bkrkin... nm + (n-2)m +

8 Liner spe Firs ide Firs ide: Keep only wo rows in memory nd reompue when oher prs of he mrix is needed durin bkrkin... nm + (n-2)m + (n-4)m

9 Liner spe Firs ide Firs ide: Keep only wo rows in memory nd reompue when oher prs of he mrix is needed durin bkrkin... nm + (n-2)m + (n-4)m

10 Liner spe Firs ide Firs ide: Keep only wo rows in memory nd reompue when oher prs of he mrix is needed durin bkrkin... nm + (n - 2)m + (n - 4)m + (n - 6)m

11 Liner spe Firs ide Firs ide: Keep only wo rows in memory nd reompue when oher prs of he mrix is needed durin bkrkin... nm + (n - 2)m + (n - 4)m + (n - 6)m

Liner spe Firs ide Firs ide: Keep only wo rows in memory nd reompue when oher prs of he mrix is needed durin bkrkin... nm + (n - 2)m + (n - 4)m + (n - 6)m + 2 12

Time nlysis (in enerel): Liner spe Ide I nm + (n-2)m + (n-4)m +... + 2m = m(n + (n-2) + (n-4) +... + 2) = Θ(mn 2 ) beuse n(n-1)/4 <= n + (n-2) + (n-4) +... + 2 <= n(n-1)/2 Firs ide: Keep only wo rows in memory nd reompue when oher prs of he mrix is needed durin bkrkin... nm + (n - 2)m + (n - 4)m + (n - 6)m + 2 13

Liner spe Firs ide 14

15 Liner spe Hirshber's ide Hirshber's ide: Find middle ede (i.e. middle olumn ) of n opiml linmen, spli ino wo subproblems nd reurse... nm

16 Liner spe Hirshber's ide Middle row Hirshber's ide: Find middle ede (i.e. middle olumn ) of n opiml linmen, spli ino wo subproblems nd reurse... nm

17 Liner spe Hirshber's ide Middle row Hirshber's ide: Find middle ede (i.e. middle olumn ) of n opiml linmen, spli ino wo subproblems nd reurse... nm

18 Liner spe Hirshber's ide Hirshber's ide: Find middle ede (i.e. middle olumn ) of n opiml linmen, spli ino wo subproblems nd reurse... nm + (n / 2)m

19 Liner spe Hirshber's ide Middle row Middle row Hirshber's ide: Find middle ede (i.e. middle olumn ) of n opiml linmen, spli ino wo subproblems nd reurse... nm + (n / 2)m

20 Liner spe Hirshber's ide Middle row Middle row Hirshber's ide: Find middle ede (i.e. middle olumn ) of n opiml linmen, spli ino wo subproblems nd reurse... nm + (n / 2)m

21 Liner spe Hirshber's ide Hirshber's ide: Find middle ede (i.e. middle olumn ) of n opiml linmen, spli ino wo subproblems nd reurse... nm + (n / 2)m + (n / 4)m

22 Liner spe Hirshber's ide Hirshber's ide: Find middle ede (i.e. middle olumn ) of n opiml linmen, spli ino wo subproblems nd reurse... nm + (n / 2)m + (n / 4)m

23 Liner spe Hirshber's ide Hirshber's ide: Find middle ede (i.e. middle olumn ) of n opiml linmen, spli ino wo subproblems nd reurse... nm + (n / 2)m + (n / 4)m

24 Liner spe Hirshber's ide Hirshber's ide: Find middle ede (i.e. middle olumn ) of n opiml linmen, spli ino wo subproblems nd reurse... nm + (n / 2)m + (n / 4)m + (n / 8)m

25 Liner spe Hirshber's ide Hirshber's ide: Find middle ede (i.e. middle olumn ) of n opiml linmen, spli ino wo subproblems nd reurse... nm + (n / 2)m + (n / 4)m + (n / 8)m

26 Liner spe Hirshber's ide Hirshber's ide: Find middle ede (i.e. middle olumn ) of n opiml linmen, spli ino wo subproblems nd reurse... nm + (n / 2)m + (n / 4)m + (n / 8)m

27 Liner spe Hirshber's ide Hirshber's ide: Find middle ede (i.e. middle olumn ) of n opiml linmen, spli ino wo subproblems nd reurse... nm + (n / 2)m + (n / 4)m + (n / 8)m

28 Time nlysis (in enerel): Liner spe Hirshber's ide nm + (n/2)m + (n/4)m +... + 2m = m(n + (n/2) + (n/4) +... + 2) = Θ(mn) beuse n <= n + (n/2) + (n/4) +... + 2 <= 2n Hirshber's ide: Find middle ede (i.e. middle olumn ) of n opiml linmen, spli ino wo subproblems nd reurse... nm + (n / 2)m + (n / 4)m + (n / 8)m

Liner spe Hirshber's ide 29

30 Liner spe Hirshber's ide Problem: Find he middle olumn (k middle ede ) in n opiml linmen in qudri ime nd liner spe... Middle row Hirshber's ide: Find middle ede (i.e. middle olumn ) of n opiml linmen, spli ino wo subproblems nd reurse... nm + (n / 2)m + (n / 4)m + (n / 8)m

31 The ineresin pr of he ble d m=+[(b-+1) div 2] b

d 32 Problem: Find he middle olumn (k middle ede ) in n opiml linmen of A[+1..b] nd B[+1..d], i.e. find he ede on n opiml The ph ineresin from node (,) o node pr (b,d) in of he linmen he ble rph whih oes from he upper hlf (reen) o he lower hlf (red) in he dynmi prormmin ble below. m=+[(b-+1) div 2] b

Problem: Find he middle olumn (k middle ede ) in n opiml linmen of A[+1..b] nd B[+1..d], i.e. find he ede on n opiml The ph ineresin from node (,) o node pr (b,d) in of he linmen he ble rph whih oes from he upper hlf (reen) o he lower hlf (red) in he dynmi prormmin ble below. d m=+[(b-+1) div 2] Soluion ide: We define funion find_ede(,b,,d,m) whih reurns he ede from row m-1 o row m on n opiml ph from (,) o ell (b,d), i.e. he "middle olumn" in n opiml linmen of A[+1..b] nd B[+1..d]. The ede n eiher be dionl ede oin from (m-1,j-1) o (m,j) or veril ede oin from (m-1,j) o (m,j) for some <=j<=d. b We denoe he wo ses s (j,diagonal) nd (j,vertical) respeively. 33

34 Implemenin find_ede(,b,,d,m) Implemenion: Define he rebk ble T[..b][..d] s (b+1)*(d-+1) ble suh h enry T[i,j] idenifies he ede on n opiml ph from (,) o (i,j) whih oes from row m-1 o row m. The ede is eiher (x,diagonal) or (x,vertical) for some <=x<=d. In priulr T[,d] is he ede whih oes from row m-1 o row m on n opiml ph from (,) o (b,d), i.e. he ede we re lookin for.

35 Implemenin find_ede(,b,,d,m) Implemenion: Define he rebk ble T[..b][..d] s (b+1)*(d-+1) ble suh h enry T[i,j] idenifies he ede on n opiml ph from (,) o (i,j) whih oes from row m-1 o row m. The ede is eiher (x,diagonal) or (x,vertical) for some <=x<=d. In priulr T[,d] is he ede whih oes from row m-1 o row m on n opiml ph from (,) o (b,d), i.e. he ede we re lookin for. Compuion: We n ompue T[,d] by fillin ou he rebk ble T[..b][..d] row by row while fillin he orrespondin ells in he dynmi prormmin ble S[..b][..d]. S: T:

36 Implemenin find_ede(,b,,d,m) Implemenion: Define he rebk ble T[..b][..d] s (b+1)*(d-+1) ble suh h enry T[i,j] idenifies he ede on n opiml ph from (,) o (i,j) whih oes from row m-1 o row m. The ede is eiher (x,diagonal) or (x,vertical) for some <=x<=d. In priulr T[,d] is he ede whih oes from row m-1 S[i-1, j-1] + subos(a[i ], B[j ]) S[i-1, j] + pos S[i, j-1] + pos 0 if i=0 nd j=0 o row m on n opiml ph from (,) o (b,d), i.e. he ede we re lookin for. S[i, j] = mx Compuion: We n ompue T[,d] by fillin ou he rebk ble T[..b][..d] row by row while fillin he orrespondin ells in he dynmi prormmin ble S[..b][..d]. S: T:

Compuin T[i,j] If i < m: T[i,j] = None. Inuiion: n opiml ph from (,)->..->(i,j) does no o from row m-1 o row m if i = m: se 1: if S[i,j] = S[i-1,j-1] + subos(a[i],b[j]): T[i,j] = (j, DIAGONAL) Inuiion: n opiml ph is (,)->..->(m-1,j-1)->(m,j) se 2: if S[i,j] = S[i-1,j] + pos: T[i,j] = (j, VERTICAL) Inuiion: n opiml ph is (,)->..->(m-1,j)->(m,j) se 3: if S[i,j] = S[i,j-1] + pos: T[i,j] = T[i,j-1] Inuiion: n opiml ph is (,)->..->(m,j-1)->(m,j) if i > m: if S[i,j] = S[i-1,j-1] + subos(a[i],b[j]): T[i,j] = T[i-1,j-1] if S[i,j] = S[i-1,j] + pos: T[i,j] = T[i-1,j] if S[i,j] = S[i,j-1] + pos: T[i,j] = T[i,j-1] Inuiion: n opiml ph is (,)->..->(h,k)->(i,j), i.e. i oes from row m-1 o row m vi he sme ede s n opiml ph (,b)->..->(h,k) 37

If i < m: Observion: We n ompue ble T row by row in liner spe. While fillin ou row i, we do no ess enries in row 0..i-2, i.e. we Compuin only need o keep wo T[i,j] rows of T in memory. (Exly like when fillin ou he dynmi prormmin ble). T[i,j] = None. Inuiion: n opiml ph from (,)->..->(i,j) does no o from row m-1 o row m if i = m: se 1: if S[i,j] = S[i-1,j-1] + subos(a[i],b[j]): T[i,j] = (j, DIAGONAL) Inuiion: n opiml ph is (,)->..->(m-1,j-1)->(m,j) se 2: if S[i,j] = S[i-1,j] + pos: T[i,j] = (j, VERTICAL) Inuiion: n opiml ph is (,)->..->(m-1,j)->(m,j) se 3: if S[i,j] = S[i,j-1] + pos: T[i,j] = T[i,j-1] Inuiion: n opiml ph is (,)->..->(m,j-1)->(m,j) if i > m: if S[i,j] = S[i-1,j-1] + subos(a[i],b[j]): T[i,j] = T[i-1,j-1] if S[i,j] = S[i-1,j] + pos: T[i,j] = T[i-1,j] if S[i,j] = S[i,j-1] + pos: T[i,j] = T[i,j-1] Inuiion: n opiml ph is (,)->..->(h,k)->(i,j), i.e. i oes from row m-1 o row m vi he sme ede s n opiml ph (,b)->..->(h,k) 38

39 Spliin ino subproblems When find_ede(,b,,d,m) hs been ompued, we hve found n ede/olumn in n opiml linmen of A[+1..b] nd B[+1..d] nd n spli he reminin linmen problem ino wo subproblems f. below nd he fiures on he followin wo slides. If find_ede(,b,,d,m) = (j,diagonal), we n spli he reminin linmen problem ino wo subproblems: find he opiml linmen of A[+1..m-1] nd B[+1..j-1] find he opiml linmen of A[m+1..b] nd B[j+1..d] If find_ede(,b,,d,m) = (j,vertical), we n spli he reminin linmen problem ino wo subproblems: find he opiml linmen of A[+1..m-1] nd B[+1..j] find he opiml linmen of A[m+1..b] nd B[j+1..d]

40 find_ede(,b,,d,m)=(j,diagonal) j d m=+[(b-+1) div 2] b

41 find_ede(,b,,d,m)=(j,vertical) j d m=+[(b-+1) div 2] b

Puin i ll oeher Overll ide: To find n opiml linmen of A[+1..b] nd B[+1..d], we ll find_ede(, b,, d, +[(b-+1) div 2]), whih yields he middle olumn, nd oninue reursively f. he previous slides by dividin ino wo subproblems. The bse se is when =b, i.e when we sk for n opiml linmen of he empy srin nd B[+1..d]. This linmen n be reurned immediely s sequene of p d-+1 olumns. Compuin n opiml linmen of A[1..n] nd B[1..n] is done by llin opiml_linmen(0,n,0,m). Pseudo ode: fun opiml_linmen(,b,,d) if ==b hen reurn linmen of empy srin nd B[+1..d] else middle ede = find_ede(,b,,d,+ [(b-+1) div 2]) reurn opiml_linmen( subproblem1 )+ middle ede + opiml_linmen( subproblem2 ) 42

43 Cves Be reful wih indies: Deide if he inpu srins A nd B re indexed from 0 (s A[0..n-1] nd B[0..m-1]) or from 1 (s A[1..n] nd B[1..m]). Deide lso if he rows nd olumns in he dynmi prormmin (nd re-bk) ble re numbered from 0 or 1. Remember nd sik o your deision. In hese slides i is ssumed h srins re indexed from 1, nd rows/olumns re numbered from 0. This mens h he sub-ble (of he dynmi prormmin ble) from row o row b (boh inluded) nd olumn o olumn d (boh inluded) orresponds o he dynmi prormmin ble for n linmen of A[+1..b] nd B[+1..d]. Be reful wih he bse se: Be sure of he definiion of your bse se (i.e. when ==b s in he pseudo ode on he previous slide) nd sik wih i.

Hirshber's find_ede(,b,,d,m) In Hirshber's oriinl pper, he does no use n ddiion ble o in order o keep rk of 'where he opiml ph eners he middle row'. Essenil he only fills ou he dynmi-prormmin ble S. S: T: Observion: Hirshber uilizes h he opiml os of n linmen of A nd B, OPT(A[1..n], B[1..m]) is equl o he opiml os of n linmen of he reversed sequenes A R [1..n] = A[n..1] nd B R [1..m] = B[m..1]: OPT(A[1..n], B[1..m]) = OPT(A R [1..n], B R [1..m]) 44

45 Hirshber's implemenion (1) Observions Tble S is he dynmi prormmin ble for linmen of A nd B, row r n be ompued in ime O(mr) nd spe O(m) by fillin ou he ble row-by-row, keepin wo rows in memory. Tble S R is he dynmi prormmin ble for linmen of A R nd B R, row r+1 of S R (ounin from he op) n be ompued in ime O(m(n-r)) nd spe O(m) by fillin ou he ble row-byrow (from he boom), keepin wo rows in memory. In summry, we n ompue 'row r of S' nd 'row r+1 of S R ' in ime O(nm) nd spe O(m). S[r, j] = OPT(A[1..r], B[1..j]) S R [r+1, j] = OPT(A[r+1..n], B[j..m]) = OPT(A R [1..n-r], B R [1..m-j+1])

Hirshber's implemenion (2) Observions Tble S is he dynmi prormmin ble for linmen of A nd B, row r n be ompued in ime O(mr) nd spe O(m) by fillin ou he ble row-by-row, keepin wo rows in memory. Tble S R is he dynmi prormmin ble for linmen of A R nd B R, row r+1 of S R (ounin from he op) n be ompued in ime O(m(n-r)) nd spe O(m) by fillin ou he ble row-byrow (from he boom), keepin wo rows in memory. The opiml os of he ph from (0,0) o (n,m) hvin (j', VERTICAL) s is 'middle ede' is: In summry, we n ompue 'row r of S' nd 'row r+1 of S R ' in ime O(nm) nd spe O(m). S[r,j'] + + S R [r+1,j'] S[r, j] = OPT(A[1..r], B[1..j]) S R [r+1, j] = OPT(A[r+1..n], B[j..m]) = OPT(A R [1..n-r], B R [1..m-j+1]) 46

Hirshber's implemenion (3) // Pseudo ode for findin middle ede oin // from row r o r+1 of n opiml linmen: S[r, j] = OPT(A[1..r], B[1..j]) mx = 0 middel_ede = (0, VERTICAL) // Mximize over ll (j, VERTICAL) for j=0 o m do urr = S[r,j] + + S R [r+1,j] if urr > m hen mx = urr middle_ede = (j, VERTICAL) endif endfor // Mximize over ll (j, DIAGONAL) for j=0 o m-1 do urr = S[r+j] + s(a[r+1],b[j+1]) + S R [r+1,j+1] if urr > mx hen mx = urr middle_ede = (j, DIAGONAL) endif endfor reurn middle_ede S R [r+1, j] = OPT(A[r+1..n], B[j..m]) = OPT(A R [1..n-r], B R [1..m-j+1]) 47

Hirshber's implemenion (4) Conlusion // Pseudo ode for findin middle ede oin // from row r o r+1 of n opiml linmen: mx = 0 middel_ede = (0, VERTICAL) // Mximize over ll (j, VERTICAL) for j=0 o m do urr = S[r,j] + + S R [r+1,j] if urr > m hen mx = urr middle_ede = (j, VERTICAL) endif endfor // Mximize over ll (j, DIAGONAL) for j=0 o m-1 do urr = S[r+j] + s(a[r+1],b[j+1]) + S R [r+1,j+1] if urr > mx hen mx = urr We n find 'middle ede' in ime O(nm) nd spe O(m), whih by reursion yields h we n ompue n opiml linmen in ime O(nm) nd spe O(m) S[r, j] = OPT(A[1..r], B[1..j]) middle_ede = (j, DIAGONAL) endif endfor reurn middle_ede S R [r+1, j] = OPT(A[r+1..n], B[j..m]) = OPT(A R [1..n-r], B R [1..m-j+1]) 48