filmov
tv
Longest common substring using Dynamic Programming | bottom-up approach
![preview_player](https://i.ytimg.com/vi/TcjljpfPPYU/maxresdefault.jpg)
Показать описание
Few years ago, I developed a yearning to grow skills in programming I came across an article which was about the DNA match of two persons.
It was stated in the article that the two DNAs are considered as very very long strings and then the job is to find common substring in two strings, once the
common substring is found the DNAs match.
It intrigued to solve this longest common substring problem on my own. With my limited talent, I came up with a naive solution of finding the longest substring between two strings. It
was working fine when the length of the strings were small but once I tested my program on strings of length beyond 200 chars, my computer jammed.
This poked me to write an optimized algorithm to find the longest common substring. I struggled and struggled until I came across this dynamic programming solution which appeared to me as nothing less than magic.
Here's the description of the problem -
Given two strings
s1 - ABCXYZAY
s2 - XYZABCD
we need to find the length of the longest common substring as well as the common substring between two strings which will be XYZA with length as 4.
This problem is different from longest common subsequence dynamic programming problem as a common substring is characters appearing continuously after one another
whereas, the common subsequence is characters appearing in the some order but not necessarily continuously.
So, let's watch this video to solve the longest common substring problem using dynamic programming.
It was stated in the article that the two DNAs are considered as very very long strings and then the job is to find common substring in two strings, once the
common substring is found the DNAs match.
It intrigued to solve this longest common substring problem on my own. With my limited talent, I came up with a naive solution of finding the longest substring between two strings. It
was working fine when the length of the strings were small but once I tested my program on strings of length beyond 200 chars, my computer jammed.
This poked me to write an optimized algorithm to find the longest common substring. I struggled and struggled until I came across this dynamic programming solution which appeared to me as nothing less than magic.
Here's the description of the problem -
Given two strings
s1 - ABCXYZAY
s2 - XYZABCD
we need to find the length of the longest common substring as well as the common substring between two strings which will be XYZA with length as 4.
This problem is different from longest common subsequence dynamic programming problem as a common substring is characters appearing continuously after one another
whereas, the common subsequence is characters appearing in the some order but not necessarily continuously.
So, let's watch this video to solve the longest common substring problem using dynamic programming.
Комментарии