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!
=== ''LCS'' function defined === Let two sequences be defined as follows: <math>X=(x_1 x_2 \cdots x_m)</math> and <math>Y=(y_1 y_2 \cdots y_n)</math>. The prefixes of <math>X</math> are <math>X_0, X_1, X_2, \dots, X_m</math>; the prefixes of <math>Y</math> are <math>Y_0, Y_1, Y_2, \dots, Y_n</math>. Let <math>\mathit{LCS}(X_i,Y_j)</math> represent the set of longest common subsequence of prefixes <math>X_i</math> and <math>Y_j</math>. This set of sequences is given by the following. :<math> \mathit{LCS}(X_i,Y_j)=\begin{cases} \epsilon & \mbox{if }i=0\mbox{ or }j=0 \\ \mathit{LCS}(X_{i-1},Y_{j-1}) \hat{} x_i & \mbox{if }i,j>0\mbox{ and }x_i=y_j \\ \operatorname{\max}\{\mathit{LCS}(X_i,Y_{j-1}),\mathit{LCS}(X_{i-1},Y_j)\} & \mbox{if }i,j>0\mbox{ and }x_i\ne y_j. \end{cases} </math> To find the LCS of <math>X_i</math> and <math>Y_j</math>, compare <math>x_i</math> and <math>y_j</math>. If they are equal, then the sequence <math>\mathit{LCS}(X_{i-1},Y_{j-1})</math> is extended by that element, <math>x_i</math>. If they are not equal, then the longest among the two sequences, <math>\mathit{LCS}(X_i,Y_{j-1})</math>, and <math>\mathit{LCS}(X_{i-1},Y_j)</math>, is retained. (If they are the same length, but not identical, then both are retained.) The base case, when either <math>X_i</math> or <math>Y_i</math> is empty, is the [[empty string]], <math>\epsilon</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)