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 41: Line 41:
 
2 + f(i+1,j-1) & \text{if } j-i > 1 \text{ and } S_i = S_{j-1}
 
2 + f(i+1,j-1) & \text{if } j-i > 1 \text{ and } S_i = S_{j-1}
 
\end{cases}</math>
 
\end{cases}</math>
 
To see calculate the cost, consider that the worst case occurs when every invocation to <math>f</math> requires a call on two different substrings. This can happen for invocations with strings of length <math>n</math> to <math>2</math>. So the total number of invocations is <math>2^{(n-1)}</math>.
 
 
However, a lot of these invocations are repeats. If we store previously computed solutions, then the cost goes down. The above worst case happens when no matches are ever made, so this requires us to try out eliminating all strings that start at 0 and those that start at n-1, such that their combined length is <math>\leq n-1</math>. This is just the number of ways to partition a given number into two non-negative integers, summed up over <math>1 ,..., n-1</math>. The number of ways to partition <math>k</math> into two non-negative integers is <math>k + 1</math>. Hence the overall cost is <math>O(n^2)</math>.
 
  
 
==References==
 
==References==

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)