forked from algorithm-visualizer/algorithm-visualizer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode.js
More file actions
36 lines (30 loc) · 900 Bytes
/
Copy pathcode.js
File metadata and controls
36 lines (30 loc) · 900 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
var i,j;
// Build the memo table in bottom up fashion
for( i = 0; i <= m; i++ ) {
for( j = 0; j <= n; j++ ) {
if ( i === 0 || j === 0 ) {
A[i][j] = 0;
} else if ( string1[i-1] == string2[j-1] ) {
tracer1._select ( i-1 )._wait ();
tracer2._select ( j-1 )._wait ();
tracer3._select ( i-1, j-1 )._wait ();
A[i][j] = A[i-1][j-1] + 1;
tracer1._deselect ( i-1 );
tracer2._deselect ( j-1 );
tracer3._deselect ( i-1, j-1 );
} else {
tracer3._select ( i-1, j )._wait ();
tracer3._select ( i, j-1 )._wait ();
if( A[i-1][j] > A[i][j-1] ) {
A[i][j] = A[i-1][j];
} else {
A[i][j] = A[i][j-1];
}
tracer3._deselect ( i-1, j );
tracer3._deselect ( i, j-1 );
}
tracer3._notify ( i, j , A[i][j] )._wait ();
tracer3._denotify( i, j );
}
}
logger._print ( 'Longest Common Subsequence is ' + A[m][n] );