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

fix for quadratic time caused by substring() in LZW compression #114

Open
inflaton opened this issue Feb 6, 2022 · 0 comments
Open

fix for quadratic time caused by substring() in LZW compression #114

inflaton opened this issue Feb 6, 2022 · 0 comments

Comments

@inflaton
Copy link

inflaton commented Feb 6, 2022

Hi Kevin,

I've made a fix for quadratic time caused by substring() in LZW compression. The key to the fix is to use a new overloaded method TST.longestPrefixOf(String query, int startIndex) in LZW.compress() method. Attached please find 3 reference files:

  1. LempelZivWelch.java: improved LZW.java

  2. TernarySearchTrie: improved TST.java

  3. lzw.sh: shell script proves the correctness and performance improvement.
    NOTE: existing LZW seems to take forever to compress dickens.txt (~29MB)

Regards,
Donghao

LZW_fix.zip

inflaton pushed a commit to inflaton/algs4 that referenced this issue Feb 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant