Recall & Review
beginner
What is the Longest Common Subsequence (LCS)?
LCS is the longest sequence that appears in the same relative order in two sequences but not necessarily contiguously.
Click to reveal answer
beginner
What is the main difference between Longest Common Subsequence and Longest Common Substring?
LCS allows characters to be non-contiguous but in order, while Longest Common Substring requires characters to be contiguous.
Click to reveal answer
intermediate
In LCS dynamic programming, what does the table cell dp[i][j] represent?
dp[i][j] stores the length of the LCS of the first i characters of string1 and first j characters of string2.
Click to reveal answer
intermediate
What is the time complexity of the classic dynamic programming solution for LCS?
The time complexity is O(m*n), where m and n are the lengths of the two input strings.
Click to reveal answer
advanced
How do you reconstruct the LCS string from the dp table after computing lengths?
Start from dp[m][n], move backwards: if characters match, add to LCS and move diagonally; else move in direction of larger dp value.
Click to reveal answer
What does the Longest Common Subsequence represent?
✗ Incorrect
LCS is the longest sequence that appears in the same order in both strings but characters do not have to be next to each other.
In LCS dynamic programming, if characters at positions i and j match, what is dp[i][j]?
✗ Incorrect
When characters match, we add 1 to the LCS length found by excluding these characters (dp[i-1][j-1] + 1).
What is the base case for the dp table in LCS?
✗ Incorrect
If one string is empty, LCS length is zero, so dp[0][j] and dp[i][0] are zero.
What is the time complexity of the classic LCS dynamic programming solution?
✗ Incorrect
The solution fills an m by n table, so time complexity is O(m*n).
Which of these is NOT true about LCS?
✗ Incorrect
LCS characters do not need to be contiguous, only in order.
Explain how to use dynamic programming to find the Longest Common Subsequence between two strings.
Think about how to build solutions for smaller prefixes of the strings.
You got /4 concepts.
Describe the process to reconstruct the actual LCS string after computing the dp table.
Trace back from the bottom-right corner of the dp table.
You got /4 concepts.