Hi, I have a code that can find the lowest common ancestor ( lowest common character) and the common chaarcters for 2 vectors, the code is:
cc= ['a0.c2.b2.d6'] ;pc= ['a0.c1.c3.d5'];for i=1:min(length(pc),length(cc)) if cc(i)==pc(i) q(i)=cc(i); else break endendif strcmp(q,pc) | strcmp(q,cc) LCA=q;elsedisp('There is no LCA')end
The problem of this code is that it takes the common character even if they are not has the same supnumber, like for eaxmple, the previous cc and pc , the answer will be :
There is no LCAq =a0.c note that it takes c as common between c2 and c1 which is not accepted. also it takes the 'dot' between character such as : cc= ['a0.c4.b2.d6'] ; pc= ['a0.c4.c3.d5']; for i=1:min(length(pc),length(cc)) if cc(i)==pc(i) q(i)=cc(i); else break end end if strcmp(q,pc) | strcmp(q,cc) LCA=q; else disp('There is no LCA') end q
the answer will be:
There is no LCAq =a0.c4.
advice me please
Best Answer