next up previous
Next: Dynamic Programming Up: CSE 2320: Algorithms and Previous: Memoization

Longest Common Subsequence (LCS)

Problem: Given two sequences X = \(\langle x_1, .., x_m \rangle\) and Y = \(\langle y_1, .., y_n \rangle\), find the longest subsequence Z = \(\langle z_1, .., z_k \rangle\) that is common to x and y.

A subsequence is a subset of elements from the sequence with strictly increasing order (not necessarily contiguous).

For example, if X = $\langle$A,B,C,B,D,A,B$\rangle$ and Y = $\langle$B,D,C,A,B,A$\rangle$, then some common subsequences are:

Brute Force: Check all 2m subsequences of X for an occurrence in Y.

Copyright © 1998 The University of Texas at Arlington