Longest common subsequence: Difference between revisions
Content added Content deleted
(Logo) |
m (→{{header|Tcl}}: Small fixes, better organization) |
||
Line 481: | Line 481: | ||
=={{header|Tcl}}== |
=={{header|Tcl}}== |
||
Both solutions translated from the Java. |
Both solutions translated from the Java. |
||
===Recursive=== |
|||
⚫ | |||
⚫ | |||
'''recursive''' |
|||
⚫ | |||
if {$a eq "" || $b eq ""} {return ""} |
if {$a eq "" || $b eq ""} {return ""} |
||
set a_ [string range $a 1 end] |
set a_ [string range $a 1 end] |
||
Line 494: | Line 493: | ||
return [expr {[string length $x] > [string length $y] ? $x :$y}] |
return [expr {[string length $x] > [string length $y] ? $x :$y}] |
||
} |
} |
||
</lang> |
}</lang> |
||
===Dynamic=== |
|||
'''dynamic''' |
|||
⚫ | |||
<lang tcl>package require Tcl 8.5 |
<lang tcl>package require Tcl 8.5 |
||
namespace import ::tcl::mathop::+ |
namespace import ::tcl::mathop::+ |
||
Line 535: | Line 535: | ||
return [string reverse $result] |
return [string reverse $result] |
||
}</lang> |
}</lang> |
||
Performance |
===Performance Comparison=== |
||
< |
<lang tcl>% time {d_lcs thisisatest testing123testing} 10 |
||
637.5 microseconds per iteration |
637.5 microseconds per iteration |
||
% time {r_lcs thisisatest testing123testing} 10 |
% time {r_lcs thisisatest testing123testing} 10 |
||
1275566.8 microseconds per iteration</ |
1275566.8 microseconds per iteration</lang> |