Add chain to tree and lcs algorithms

This is done to prepare for the fast matcher.