Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
flaviusm,

your problem is in principle NP-hard. However, the hardest part of the problem is to determine whether a word is "unmoved" (these are the unmarked ones in my output, see also Re^3: diff of two strings). This can be done in O(nm) with this dynamic programming ansatz. How the words are finally printed out in printDiff based for example on uniqueness (insertion, but only in the second string) or moved position (in both strings, but a insertion/deletion) are IMHO trivial changes.

I do not understand your note and I still think the LCS is the way to go. Do you understand the algorithm? If yes, then please tell my why or when the LCS fails.

If you really want to use common substrings to construct a skeleton, try Tree::Suffix, which is also mentioned in my String::LCSS_XS module. But keep in mind that these modules are character based (so they are much slower without any re-encoding tricks) and that the free suffix tree/array implementations are in general not as good as they could be. Optimizing the lcs algorithm in C is really easy. See the wikipedia article for details. With the linear memory modification, the data should even fit in the cache for not too large strings.


In reply to Re^5: diff of two strings by lima1
in thread diff of two strings by flaviusm

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (1)
As of 2024-04-24 14:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found