Search the courses, subjects, tracks, games and features, or jump straight to a page.
Learn it your way
A short class with Sarah and her students. The other ways are under More.
Sign up free to listen. Transcripts are free to read.
Today we're going to explore the problem of finding the longest common subwords between two sequences. Can anyone tell me what a subword is?
Is it a part of a word, like a segment?
Exactly! A subword is indeed a segment that can appear in both strings. For example, in the words 'secret' and 'secretary', the segment 'secret' is a common subword.
What about the lengths of these common subwords?
Good question! Our focus today will also cover how to compute the lengths of these common subwords efficiently.
We can solve the longest common subword problem using brute force, but that can be slow. Can anyone suggest why?
Because it checks every possible combination?
Exactly! This approach has a high time complexity. That's why we look towards a more efficient solution—dynamic programming. It helps us break the problem into smaller, manageable subproblems.
How does that work?
We build a table to track the lengths of common subwords at various positions, allowing us to compute the solution progressively.
Now, let's discuss an essential concept called inductive observation. If we find a common letter at two positions, what can we infer about the lengths of common subwords?
That the length of the common subword increases by one?
That's correct! If the letters match, then we can say there is a common subword of length k at those positions, which implies there’s also a common subword of length k-1 starting one position forward.
But what happens when they don't match?
Exactly! In that case, we conclude that there cannot be a common subword at those positions.
Finally, let's look at how we fill out the dynamic programming table with the common subwords. How do we start filling in the values?
By initializing the last row and column to zero?
Yes! We initialize to zero since an empty substring has no matching segments. Then we fill the table by checking character matches and using our inductive observations.
And where do we find the length of the longest common subword?
Great question! We look for the highest value in the table once it's completed.
The longest segment that appears in both sequences.
A straightforward approach that checks every possible segment, often inefficient.
A more efficient method that divides the problem into subproblems and uses their solutions.
A way to reason about subword lengths by establishing conditions based on character matches.
To find a common word, look for the letters that sound the same; the correct segments are part of the game.
Once, two words named 'director' and 'secretary' met at a park. They discovered that by examining their letters closely, they had hidden segments that made them closer, revealing shared stories of 'ec' and 're'.
Use 'DIP' for dynamic programming: Decompose, Identify, and Process.
LCS = Longest Common Subword.
Term
What is a longest common subword?
Click to flip
Term
Explain inductive observation.
Click to flip
Term
What does dynamic programming do?
Click to flip
Term
What is a brute force approach?
Click to flip
A segment of a word that occurs in another word.
The longest segment that appears in both strings.
A method for solving complex problems by breaking them down into simpler subproblems.
Method of reasoning where the conclusion is based on observing patterns in specific cases.
A straightforward method that tries all possible combinations to find a solution.
This section focuses on the problem of finding the lengths of the longest common subwords between two sequences using inductive reasoning.
In this section, the concept of longest common subwords is introduced, where the problem involves finding segments that appear in both sequences. Various methods to solve this problem are discussed, including brute force and dynamic programming approaches.
This section delves into the problem of finding the longest common subwords and subsequences between two sequences. With the aid of examples like 'secret' and 'secretary' or 'bisect' and 'trisect', we illustrate how common segments can be identified within two strings. The aim is to compute the length of these longest common subwords rather than the subwords themselves.
The chapter discusses a brute force algorithm that considers every combination of positions within the two strings. However, the efficiency of this method is poor due to its O(m*n^2) time complexity.
To improve the efficiency, the section introduces an inductive observation, which relies on establishing commonalities between subwords. It forms the basis for a more efficient dynamic programming solution. In this approach, we define subproblems that relate the lengths of the common subwords at different positions in the strings using recursion.
The discussion further covers boundary conditions, where if one word is empty, the length of the common subword is 0. The section also presents a code example and emphasizes the dynamic programming table's construction for tracking lengths of common subwords, culminating in an efficient algorithm to solve the longest common subword problem.