From: Reducing the worst case running times of a family of RNA and CFG problems, using Valiant’s approach
Outside-VMT (s, β) |
---|
1: Allocate a matrix A of size ||s|| × ||s||, and initialize all entries in A with ϕ elements. |
2: Call Compute-Outside-Sub-Matrix ([0, n], [0, n]), where n is the length of s. |
3: return A |
Compute-Outside-Sub-Matrix (I, J) |
pre-condition: The values in A[0,I], [J,n], excluding the values in A I,J , are computed. |
If μ i,j = ⊕q∈[0,i)(β q,i ⊗ α q,j ), then A I,J = (β[0,I),I)T ⊗ α[0,I),J. Else, if μ i,j = ⊕q∈(j,n](α i,q ⊗ β j,q ), then A I,J = αI,(J,n]⊗ (βJ,(J,n])T. |
post-condition: A[0,I], [J,n]= α[0,I], [J,n]. |
1: if I = [i, i] and J = [j, j] then |
2: If i ≤ j, compute α i,j (in o (||s||) running time) by querying computed values in A and the value μ i,j which is stored in A i,j . Update A i,j ← α i,j . |
3: else |
4: if |I| ≤ |J| then |
5: Let J1 and J2 be the two intervals such that J2J1 = J, and |J2| = ⌊|J|/2⌋. |
6: Call Compute-Outside-Sub-Matrix (I, J1). |
7: if μ i,j is of the form ⊕q∈(j,n](α i,q ⊗ β j,q ) then |
8: Let L be the interval such that L(J, n] = (J2, n]. |
9: Update . |
10: end if |
11: Call Compute-Outside-Sub-Matrix (I, J2). |
12: else |
13: Let I1 and I2 be the two intervals such that I1I2 = I, and |I1| = ⌊|I|/2⌋. |
14: Call Compute-Outside-Sub-Matrix (I1, J). |
15: if μ i,j is of the form ⊕q∈[0,i)(β q,i ⊗ α q,j ) then |
16: Let L be the interval such that [0, I)L = [0, I2). |
17: Update . |
18: end if |
19: Call Compute-Outside-Sub-Matrix (I2, J). |
20: end if |
21: end if |