Editing Longest palindromic subsequence

Jump to: navigation, search

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision Your text
Line 17: Line 17:
 
==Algorithm==
 
==Algorithm==
 
===LCS-based approach===
 
===LCS-based approach===
The standard algorithm for computing a longest palindromic subsequence of a given string <var>S</var> involves first computing a [[longest common subsequence]] (LCS) of <var>S</var> and its reverse <var>S'</var>. Often, this gives a correct LPS right away. For example, the reader may verify that '''alala''', '''afafa''', '''aflfa''' and '''alfla''' are all LCSes of '''alfalfa''' and its reverse '''aflafla'''. However, this is not ''always'' the case; for example, '''afala''' and '''alafa''' are ''also'' LCSes of '''alfalfa''' and its reverse, yet neither is palindromic. While it is clear that any LPS of a string is an LCS of the string and its reverse, the converse is false.
+
The standard algorithm for computing a longest palindromic subsequence of a given string <var>S</var> involves first computing a [[longest common subsequence]] (LCS) of <var>S</var> and its reverse <var>S'</var>. Often, this gives a correct LPS right away. For example, the reader may verify that '''alala''' and '''afafa''' are both LCSes of '''alfalfa''' and its reverse '''aflafla'''. However, this is not ''always'' the case; for example, '''afala''' and '''alafa''' are ''also'' LCSes of '''alfalfa''' and its reverse, yet neither is palindromic. While it is clear that any LPS of a string is an LCS of the string and its reverse, the converse is false.
  
 
However, with a slight modification, this algorithm can be made to work. We will use the example string '''ABCDEBCA''', which has six LPSes: '''ABCBA''', '''ABDBA''', '''ABEBA''', '''ACDCA''', '''ACECA''' and '''ACBCA''' (and our objective is to find one of them). Suppose that we find an LCS which is not one of these, such as <var>L</var>&nbsp;=&nbsp;'''ABDCA''':
 
However, with a slight modification, this algorithm can be made to work. We will use the example string '''ABCDEBCA''', which has six LPSes: '''ABCBA''', '''ABDBA''', '''ABEBA''', '''ACDCA''', '''ACECA''' and '''ACBCA''' (and our objective is to find one of them). Suppose that we find an LCS which is not one of these, such as <var>L</var>&nbsp;=&nbsp;'''ABDCA''':

Please note that all contributions to PEGWiki are considered to be released under the Attribution 3.0 Unported (see PEGWiki:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!

Cancel | Editing help (opens in new window)