Блог пользователя zuizui_123

Автор zuizui_123, 13 лет назад, По-английски

A few days ago, I found an article about algorithm of finding Longest Common Subsequence (LCS). Here is its link: https://docs.google.com/viewer?a=v&q=cache:3xhhf3n6TEMJ:www.sms.edu.pk/journals/jprm/jprmvol4/jprm9_4.pdf+&hl=vi&gl=vn&pid=bl&srcid=ADGEESiYAIGwMFziedBggqJPQN8ipIweV-KZUqCOnGA2ZnweAV3wNM11uQNC7HF4tYyTFvUhebP2BszIKI5m-ZYnF4O7t6MBtR0QV8ZJlzOI3T1Ex_mmnd2fiyhPaf0-lxsF0W-1wUu8&sig=AHIEtbR2Uaubbu_0sd9HzfW0NsQNFFYmhg

The article mentions an algorithm of O(n) for finding LCS of two strings X and Y (m is length of X, n is length of Y) with preprocessing of O(m). This algorithm is a greedy approach to solve LCS. I think it is very interesting and decide to learn it fully. But I stuck in implementation of this algorithm. I did try to write code for it but I can't do it correctly.

I hope somebody can help me for this algorithm's implementation. Thank you very much!

Thanks for reading!

  • Проголосовать: нравится
  • +4
  • Проголосовать: не нравится

»
13 лет назад, скрыть # |
 
Проголосовать: нравится +5 Проголосовать: не нравится

This greedy approach doesn't seem always producing the best answer. On pair of strings ('bcaaaa', 'aaaabc') it will find 'bc' as longest common subsequence, not 'aaaa'. Are you still sure you want this algorithm? Maybe you should use classic dynamic programming approach?