Skip to content

Commit 252a10a

Browse files
authored
Merge pull request algorithm-visualizer#208 from archie94/lcs-revise
Improved visualization for LCS
2 parents 8ec07b2 + da95a9f commit 252a10a

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

Lines changed: 22 additions & 1 deletion
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy