Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve LCS #7

Open
briancavalier opened this issue Apr 29, 2014 · 0 comments
Open

Improve LCS #7

briancavalier opened this issue Apr 29, 2014 · 0 comments

Comments

@briancavalier
Copy link
Member

The LCS algorithm for array diffing works well, but could be made more efficient by combining the lcs construction and the subsequent reduce, and by returning early in cases where it's not necessary to create the lcs matrix:

  1. Two passes are done on the common prefix. Could be reduced to 1 pass if lcs() and reduce() are combined.
  2. The LCS matrix construction can be skipped entirely when the common prefix + suffix length === a.length or b.length (or both). When:
    1. prefix+suffix length === a.length === b.length, can return immediately. No work to do.
    2. prefix+suffix length === a.length, can emit remaining span of b as additions
    3. prefix+suffix length === b.length, can emit remaining span of a as removals
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant