Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Longest common subsequence
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== Example === Let <math>X</math> be β<code>XMJYAUZ</code>β and <math>Y</math> be β<code>MZJAWXU</code>β. The longest common subsequence between <math>X</math> and <math>Y</math> is β<code>MJAU</code>β. The table <code>C</code> shown below, which is generated by the function <code>LCSLength</code>, shows the lengths of the longest common subsequences between prefixes of <math>X</math> and <math>Y</math>. The <math>i</math>th row and <math>j</math>th column shows the length of the LCS between <math>X_{1..i}</math> and <math>Y_{1..j}</math>. {| class="wikitable" style="text-align: center;" |- ! colspan="2" rowspan="2" | ! 0 !! 1 !! 2 !! 3 !! 4 !! 5 !! 6 !! 7 |- ! Ξ΅ !! M !! Z !! J !! A !! W !! X !! U |- ! 0 !! Ξ΅ | style="background:yellow" | '''0''' || 0 || 0 || 0 || 0 || 0 || 0 || 0 |- ! 1 !! X | style="background:yellow" | 0 || 0 || 0 || 0 || 0 || 0 || 1 || 1 |- ! 2 !! M | 0 || style="background:yellow" | '''1''' || style="background:yellow" | 1 || 1 || 1 || 1 || 1 || 1 |- ! 3 !! J | 0 || 1 || 1 || style="background:yellow" | '''2''' || 2 || 2 || 2 || 2 |- ! 4 !! Y | 0 || 1 || 1 || style="background:yellow" | 2 || 2 || 2 || 2 || 2 |- ! 5 !! A | 0 || 1 || 1 || 2 || style="background:yellow" | '''3''' || style="background:yellow" | 3 || style="background:yellow" | 3 || 3 |- ! 6 !! U | 0 || 1 || 1 || 2 || 3 || 3 || 3 || style="background:yellow" | '''4''' |- ! 7 !! Z | 0 || 1 || 2 || 2 || 3 || 3 || 3 || style="background: yellow" | 4 |} The <span style="background: yellow">highlighted</span> numbers show the path the function <code>backtrack</code> would follow from the bottom right to the top left corner, when reading out an LCS. If the current symbols in <math>X</math> and <math>Y</math> are equal, they are part of the LCS, and we go both up and left (shown in '''bold'''). If not, we go up or left, depending on which cell has a higher number. This corresponds to either taking the LCS between <math>X_{1..i-1}</math> and <math>Y_{1..j}</math>, or <math>X_{1..i}</math> and <math>Y_{1..j-1}</math>.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)