[Algorithm] Is s1 subsequence of s2 (DP/LCS/C++)

Changjin
Jan 3, 2021

Hello! Today we’ll looking at how to determine

if string s1 is a subsequence of s2

This can be easily solved by DP-LCS. Notice that the Longest Common Subsequence(LCS) would give the common subsequence of s1 and s2 with the maximum length. To see if s1 is a subsequence of s2, check if LCS(s1,s2)==s1 or length(LCS(s1,s2))==length(s1).

For example, LCS(“ab”,”awerb”) would give “ab”. The code implementation is straight-forward.

Time Complexity: O(n*m)

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Changjin
Changjin

No responses yet

Write a response