Skip to content

Commit da95a9f

Browse files
committed
Improved visualization for LIS
1 parent 8ec07b2 commit da95a9f

File tree

1 file changed

+22
-1
lines changed
  • algorithm/dp/longest_common_subsequence/basic

1 file changed

+22
-1
lines changed

algorithm/dp/longest_common_subsequence/basic/code.js

+22-1
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,25 @@ var i,j;
3333
}
3434
}
3535

36-
logger._print ( 'Longest Common Subsequence is ' + A[m][n] );
36+
var finalString = '';
37+
i=m;
38+
j=n;
39+
while( i>=1 && j>=1 ) {
40+
41+
tracer3._select ( i, j )._wait ();
42+
if( string1[i-1] == string2[j-1] ) {
43+
tracer1._select ( i-1 )._wait ();
44+
tracer2._select ( j-1 )._wait ();
45+
46+
finalString = string1[i-1] + finalString;
47+
i--;
48+
j--;
49+
} else if( A[i-1][j] > A[i][j-1] ) {
50+
i--;
51+
} else {
52+
j--;
53+
}
54+
}
55+
56+
logger._print ( 'Longest Common Subsequence Length is ' + A[m][n] );
57+
logger._print ( 'Longest Common Subsequence is ' + finalString );

0 commit comments

Comments
 (0)