Sentences about Greatest Common Subsequence

  • Context: MHB 
  • Thread starter Thread starter evinda
  • Start date Start date
  • Tags Tags
    Subsequence
Click For Summary

Discussion Overview

The discussion revolves around the concept of the greatest common subsequence (GCS) of two sequences, exploring its definition, properties, and implications in various scenarios. Participants examine specific cases and definitions, questioning the relevance of certain conditions and the order of elements in sequences.

Discussion Character

  • Exploratory
  • Technical explanation
  • Debate/contested

Main Points Raised

  • Some participants discuss the definition of the greatest common subsequence and its implications for the order of elements in sequences.
  • There is a proposal that if the last elements of two sequences are equal, the GCS can be derived from the GCS of the sequences without those last elements.
  • Others argue that if the last elements are different, the GCS may still be derived from the remaining elements, but this raises questions about the order and existence of subsequences.
  • One participant cites a textbook definition and examples to illustrate what constitutes a common subsequence versus a GCS, emphasizing the importance of length.
  • There is a discussion about the terminology of "greatest" versus "maximal" in the context of subsequences, with some participants suggesting that the term GCS may be misleading.
  • Participants express uncertainty about whether certain subsequences exist in the given order within the sequences.

Areas of Agreement / Disagreement

Participants do not reach a consensus on several points, including the relevance of certain conditions for the GCS, the definition of subsequences, and the terminology used. Multiple competing views remain regarding the implications of the last elements of the sequences and the order of subsequences.

Contextual Notes

Some participants note that the definitions and examples provided may depend on specific interpretations of subsequences and their properties, leading to differing conclusions about the existence and order of subsequences.

evinda
Gold Member
MHB
Messages
3,741
Reaction score
0
Hello! (Wave)

Let $X=<x_1,x_2, \dots , x_m>$ and $Y=<y_1,y_2, \dots, y_n>$ be sequences and let $Z=<z_1, z_2, \dots, z_k>$ a greatest common subsequence(GCS) of $X$ and $Y$.Then:

  1. If $x_m=y_n$,then $z_k=x_m=y_n$ and $Z_{k-1}$ is a GCS of $X_{m-1}$ and $Y_{n-1}$.
  • If $x_m \neq y_n$ and $z_k \neq x_m$,then $Z_{k-1}$ is a GCS of $X_{m-1}$ and $Y$.

Could you explain me the above sentences? (Thinking)

If we conclude at the first sentence that $Z_{k-1}$ is a GCS of $X_{m-1}$ and $Y_{n-1}$,does this mean that we take into consideration the order of the elements of the sequences? (Thinking)

Also, at the second sentence,do we consider that $n<m$ and that $k=m$ ? (Thinking)
 
Physics news on Phys.org
To be on the safe side, it would be best to have the definition of the greatest common subsequence.

evinda said:
If we conclude at the first sentence that $Z_{k-1}$ is a GCS of $X_{m-1}$ and $Y_{n-1}$,does this mean that we take into consideration the order of the elements of the sequences?
We take into account the order of elements in a sequence even if we don't conclude that $Z_{k-1}$ is a GCS of $X_{m-1}$ and $Y_{n-1}$. That's what sequence means.

evinda said:
Also, at the second sentence,do we consider that $n<m$ and that $k=m$ ?
I don't think this is relevant.
 
Evgeny.Makarov said:
To be on the safe side, it would be best to have the definition of the greatest common subsequence.

We take into account the order of elements in a sequence even if we don't conclude that $Z_{k-1}$ is a GCS of $X_{m-1}$ and $Y_{n-1}$. That's what sequence means.

I don't think this is relevant.

According to my textbook:

"For two given sequences $X$ and $Y$,we say that a sequence $Z$ is a common subsequence of $X$ and $Y$,if it is a subsequence of $X$ and of $Y$.For example, if $X=<A,B,C,B,D,A,B>$ and $Y=<B,D,C,A,B,A>$,the sequence $<B,C,A>$ is a common subsequence of $X$ and $Y$.However, $<B,C,A>$ is not a GCS of $X$ and $Y$,because its length is $3$,but the sequence $<B,C,B,A>$,that is also common at $X$ and $Y$,has length $4$.The sequence $<B,C,B,A>$ is a GCS of $X$ and $Y$,as also the sequence $<B,D,A,B>$,because there is no common subsequence with length $5$ or with a greater length.

At the problem of the GCS,we are given two sequences $X=<x_1,x_2, \dots ,x_m>$ and $Y=<y_1, y_2, \dots, y_n>$ and we are asked to find a common subsequence of $X$ and $Y$,with the greatest possible length. "If we consider for example this GCS: $<B,C,B,A>$,we see that $x_m \neq y_n$ and $z_k \neq x_m$,so we are at the second case,right?
So..does this mean that $Z_{k-1}$ is a GCS of $X_{m-1}$ and $Y$ ?
But,the subsequence $<B,C,B>$ does not exist at $Y$ in this order..

So,do we not take the order into consideration? (Thinking)
 
evinda said:
If we consider for example this GCS: $<B,C,B,A>$,we see that $x_m \neq y_n$ and $z_k \neq x_m$,so we are at the second case,right?
Yes.

evinda said:
But,the subsequence $<B,C,B>$ does not exist at $Y$ in this order.
So, you don't object to the textbook's claim that $\langle B,C,B,A\rangle$ is the GCS of $X=\langle A,B,C,B,D,A,B\rangle$ and $Y=\langle B,D,C,A,B,A\rangle$, but you do object that $\langle B,C,B\rangle$ is a subsequence of $Y$? Isn't the relation "is a subsequence of" transitive? I suggest you review the definition of subsequence in your textbook or in Wikipedia (see also the note at the bottom about the difference between a subsequence and a substring) and explain why you think that $\langle B,C,B\rangle$ is not a subsequence of $Y$.

evinda said:
  1. If $x_m=y_n$,then $z_k=x_m=y_n$ and $Z_{k-1}$ is a GCS of $X_{m-1}$ and $Y_{n-1}$.
  • If $x_m \neq y_n$ and $z_k \neq x_m$,then $Z_{k-1}$ is a GCS of $X_{m-1}$ and $Y$.
I am not sure I agree with 2. Let $X=\langle 1,2,3\rangle$ and $Y=\langle1,4,2,5\rangle$. Then the GCS of $X$ and $Y$ is $Z=\langle 1,2\rangle$. Also, the last elements of $X$ and $Y$ are different, and so are the last elements of $X$ and $Z$, so we are in a situation described by proposition 2. I also agree that $Z_{k-1}=\langle 1\rangle$ is a subsequence of $X_{m-1}$ and $Y$, but it is not the longest common subsequence: $Z$ is.

evinda said:
At the problem of the GCS,we are given two sequences $X=<x_1,x_2, \dots ,x_m>$ and $Y=<y_1, y_2, \dots, y_n>$ and we are asked to find a common subsequence of $X$ and $Y$,with the greatest possible length. "
Just a remark concerning terminology. There is a difference between "greatest" and "maximal". The greatest element is greater than everything else, while a maximal element is such that no greater element exists. The difference happens when the order is not linear and some elements are not comparable. For example, if sets are compared by inclusion, then the family of all subsets of some set $A$ has the greatest element: $A$ itself, since $A\subseteq A$. On the other hand, the family of proper subsets has many maximal subsets but no greatest subset. If you remove one element from $A$, you get a maximal proper subset: there is no greater proper subset. But maximal subsets obtained in this way are not comparable.

In this sense, "the greatest common divisor" is a correct term because that divisor is indeed greater than all other common divisors (and is even divisible by them). Note, however, that in a partial order, the greatest element is unique. Indeed, if $x$ and $y$ are two greatest elements, then $x\ge y$ and $y\ge x$, which implies $x=y$ by antisymmetry. Your textbook says that there can be two greatest common subsequences, which is possible because they should be more precisely called "common subsequences of greatest length". We don't compare subsequences themselves, in which case the greatest subsequence can be only one; we compare their lengths. In this sense, the name GCS is somewhat confusing. The Wikipedia link above calls a GCS "longest common subsequence", which makes more sense.

P.S. Hint: In typed text, every period and comma must be followed by a space.
 
Evgeny.Makarov said:
Yes.

So, you don't object to the textbook's claim that $\langle B,C,B,A\rangle$ is the GCS of $X=\langle A,B,C,B,D,A,B\rangle$ and $Y=\langle B,D,C,A,B,A\rangle$, but you do object that $\langle B,C,B\rangle$ is a subsequence of $Y$? Isn't the relation "is a subsequence of" transitive? I suggest you review the definition of subsequence in your textbook or in Wikipedia (see also the note at the bottom about the difference between a subsequence and a substring) and explain why you think that $\langle B,C,B\rangle$ is not a subsequence of $Y$.

I am not sure I agree with 2. Let $X=\langle 1,2,3\rangle$ and $Y=\langle1,4,2,5\rangle$. Then the GCS of $X$ and $Y$ is $Z=\langle 1,2\rangle$. Also, the last elements of $X$ and $Y$ are different, and so are the last elements of $X$ and $Z$, so we are in a situation described by proposition 2. I also agree that $Z_{k-1}=\langle 1\rangle$ is a subsequence of $X_{m-1}$ and $Y$, but it is not the longest common subsequence: $Z$ is.

Just a remark concerning terminology. There is a difference between "greatest" and "maximal". The greatest element is greater than everything else, while a maximal element is such that no greater element exists. The difference happens when the order is not linear and some elements are not comparable. For example, if sets are compared by inclusion, then the family of all subsets of some set $A$ has the greatest element: $A$ itself, since $A\subseteq A$. On the other hand, the family of proper subsets has many maximal subsets but no greatest subset. If you remove one element from $A$, you get a maximal proper subset: there is no greater proper subset. But maximal subsets obtained in this way are not comparable.

In this sense, "the greatest common divisor" is a correct term because that divisor is indeed greater than all other common divisors (and is even divisible by them). Note, however, that in a partial order, the greatest element is unique. Indeed, if $x$ and $y$ are two greatest elements, then $x\ge y$ and $y\ge x$, which implies $x=y$ by antisymmetry. Your textbook says that there can be two greatest common subsequences, which is possible because they should be more precisely called "common subsequences of greatest length". We don't compare subsequences themselves, in which case the greatest subsequence can be only one; we compare their lengths. In this sense, the name GCS is somewhat confusing. The Wikipedia link above calls a GCS "longest common subsequence", which makes more sense.

P.S. Hint: In typed text, every period and comma must be followed by a space.

I found the theorem,that I wrote in my first post,in my notes.But..now I found the same theorem in my textbook and noticed that the former had some mistakes.. :eek:

According to my textbook:

Let $X=<x_1,x_2,…,x_m>$ and $Y=<y_1,y_2,…,y_n>$ be sequences and let $Z=<z_1,z_2,…,z_k>$ a longest common subsequence (LCS) of $X$ and $Y$.Then:

  • If $x_m=y_n$,then $z_k=x_m=y_n$ and $Z_{k-1}$ is a LCS of $X_{m-1}$ and $Y_{n-1}$
  • If $x_m \neq y_n$ and $z_k \neq x_m$,it implies that $Z$ is a LCS of $X_{m-1}$ and $Y$

  • I still haven't understood why $x_m=y_n \Rightarrow z_k=x_m=y_n$. (Thinking)
    If we have for example $X=<A,B,E,A,F,A>$ and $Y=<D,F,B,A>$, should the last element of $Z$ be $A$,or can it also be $F$ or $B$ and we could write $A$ at which position we want?
  • At the second sentence,why do we conclude that $Z$ is a LCS of $X_{m-1}$ and $Y$ ?

(Thinking)
 
evinda said:
Let $X=<x_1,x_2,…,x_m>$ and $Y=<y_1,y_2,…,y_n>$ be sequences and let $Z=<z_1,z_2,…,z_k>$ a longest common subsequence (LCS) of $X$ and $Y$.Then:

  • If $x_m=y_n$,then $z_k=x_m=y_n$ and $Z_{k-1}$ is a LCS of $X_{m-1}$ and $Y_{n-1}$
  • If $x_m \neq y_n$ and $z_k \neq x_m$,it implies that $Z$ is a LCS of $X_{m-1}$ and $Y$
This seems more credible.

evinda said:
[*] I still haven't understood why $x_m=y_n \Rightarrow z_k=x_m=y_n$.
If the last elements of $X$ and $Y$ coincide, then why not include it in the longest common subsequence? Without that last element the common subsequence would not be the longest.

evinda said:
If we have for example $X=<A,B,E,A,F,A>$ and $Y=<D,F,B,A>$, should the last element of $Z$ be $A$,or can it also be $F$ or $B$ and we could write $A$ at which position we want?
The longest common subsequences of $X$ and $Y$ are $\langle F,A\rangle$ and $\langle B,A\rangle$. Indeed, looking at $Y$, we see that $D$ does not occur in $X$, so it can't be in an LCS. If an LCS starts with an $F$, then from $X$ it can only be $\langle F\rangle$ or $\langle F,A\rangle$, the second of which is longer. Finally, an LCS can start with a $B$, then it is $\langle B,A\rangle$.
 
Evgeny.Makarov said:
If the last elements of $X$ and $Y$ coincide, then why not include it in the longest common subsequence? Without that last element the common subsequence would not be the longest.

I understand.. (Nod)
Evgeny.Makarov said:
The longest common subsequences of $X$ and $Y$ are $\langle F,A\rangle$ and $\langle B,A\rangle$. Indeed, looking at $Y$, we see that $D$ does not occur in $X$, so it can't be in an LCS. If an LCS starts with an $F$, then from $X$ it can only be $\langle F\rangle$ or $\langle F,A\rangle$, the second of which is longer. Finally, an LCS can start with a $B$, then it is $\langle B,A\rangle$.

Isn't the longest common subsequence of $X$ and $Y$: $<A,B,F>$ ? (Thinking) Or am I wrong?
 
evinda said:
Isn't the longest common subsequence of $X$ and $Y$: $<A,B,F>$ ?
$\langle A,B,F\rangle$ is not a subsequence of $Y=\langle D,F,B,A\rangle$. In post #4 I recommended looking up the definition of the term "subsequence".
 
Evgeny.Makarov said:
$\langle A,B,F\rangle$ is not a subsequence of $Y=\langle D,F,B,A\rangle$. In post #4 I recommended looking up the definition of the term "subsequence".

A ok..I got it now!Thank you very much! (Smile)
 

Similar threads

  • · Replies 12 ·
Replies
12
Views
3K
  • · Replies 14 ·
Replies
14
Views
2K
  • · Replies 15 ·
Replies
15
Views
2K
  • · Replies 10 ·
Replies
10
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 18 ·
Replies
18
Views
3K
Replies
1
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K