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.
Class, today we are going to learn about common subwords. Can anyone tell me what a subword is?
I think a subword is a part of a word?
Exactly! A subword is a contiguous segment of a word. For instance, in the word 'secret', 'sec' is a subword. Now, what do you think about finding a common subword?
Is it a part that appears in two different words?
Correct! Common subwords appear in both words. For example, 'secret' and 'secretary' share the common subword 'secret'.
Let's remember this as the subword-segment relationship. Can anyone give me another example?
How about 'bisect' and 'trisect'—they have 'isect' as a common subword?
Great example! Keep this in mind as we dive deeper.
Now, let’s discuss the brute-force method for finding the longest common subword. Can anyone suggest how we might do that?
We could check each letter in both words?
Yes! We look at all possible starting positions in both words. If we run this algorithm, what will the complexity be?
It sounded like O(m * n²) from the lecture?
Exactly! M is the length of one word, and N is the length of the other. This means for each character, we are checking every other character until we reach a mismatch.
To enhance our method, we can use an inductive approach. Who can explain how this works?
We can compare letters and then reduce the problem size?
Absolutely! If we find a match, we can add to the length and continue comparing. What if they don't match?
Then we just stop and start over from the next letters?
Right! This allows us to significantly reduce unnecessary checks.
Finally, we arrive at the dynamic programming solution. Can someone describe this approach.
We use a table to store common subword lengths?
Correct! Each cell in the table corresponds to subproblems that we build upon. How do we populate this table, for example?
We check characters and if they match, we store the value from the diagonal plus one?
Exactly! And when they do not match, the length remains zero. This is efficient!
Now that we know how to find the length, who can tell me how we extract the common subword?
Do we trace back through the table?
Great job! We trace our steps back through the table, leveraging the information we’ve accumulated.
So, we follow the diagonal we mentioned earlier?
Exactly! The diagonal elements represent parts of our common subword.
This tracing allows us to see all candidates for the longest subword.
Correct! This understanding can reinforce your approach in algorithm design.
In summary, we defined subwords, discussed the brute-force method, transitioned to induction, and wrapped it up with dynamic programming while exploring subword extraction!
In searching for a word that's common, look for segments, let’s keep it fun; a subword's where two words align, for longest matching, we'll combine.
Imagine two friends, Alice and Bob, who have overlapping stories. They want to find the longest part of their tales that matches. By sharing and checking their writings, they discover 'adventure' is a common theme!
Subwords in two: Stand for Similarity; Underline the Basics!
LCS - Longest Common Subword, helps to remember it's all about those matching segments!
Term
What is a subword?
Click to flip
Term
What does longest common subword mean?
Click to flip
A contiguous segment of a word.
The longest contiguous segment found in two words.
An exhaustive search method that checks all positions.
An optimization approach that solves problems by breaking them down into simpler subproblems.
A method of proving a property for all integers by establishing it for the base case and an arbitrary case.
This section discusses the problem of finding the longest common subword between two sequences, detailing the brute-force and dynamic programming approaches.
In this section, we explore the longest common subword problem, highlighting how to compute the length of the longest subword using brute-force methods and introducing a more efficient dynamic programming approach. This includes detailed examples and structures to visualize and solve the problem significantly.
In this section, we delve deep into the problem of finding the longest common subword between two sequences of characters, typically strings. A subword is defined as a contiguous segment of a word. For example, in the words 'secret' and 'secretary', the longest common subword is 'secret', which has a length of 6.
The section begins by formalizing the problem by denoting two strings and defining what a common subword is. The initial focus is on creating a brute-force algorithm that examines all possible starting positions in both words, leading to a time complexity of O(m * n^2).
Next, the section introduces an inductive approach to improve the efficiency of finding the longest common subword. The key principle here is utilizing the recursive property—if we find a match at positions a_i and b_j, we can extend the search to the next characters in both strings. If they do not match, we seek the next potential starting position, thereby constructing a more efficient search mechanism.
The section concludes with a dynamic programming approach. It proposes the use of a two-dimensional table to store subproblem solutions—where each cell represents the length of the longest common subword found so far. By systematically updating this table, we can derive both the length of the longest common subword and easily backtrack to extract the subword itself. This yields a more efficient solution compared to the brute-force method, eliminating unnecessary computations.