Skip to content

Problem on article Manacher's Algorithm - Finding all sub-palindromes in O(N) #1372

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

Open
BYTE128 opened this issue Oct 20, 2024 · 3 comments
Assignees

Comments

@BYTE128
Copy link

BYTE128 commented Oct 20, 2024

Article: Manacher's Algorithm - Finding all sub-palindromes in O(N)

Problem:

Below line ->

p[i] = max(0, min(r - i, p[l + (r - i)]));

in manacher_odd function, is max(0, ..) check really required?

As I tried some examples on paper, it seemed every time, the least value of p[i] = min(r - i, p[l + (r - i)]) is 0, so, can we write directly,

p[i] = min(r - i, p[l + (r - i)]);

@mhayter
Copy link
Contributor

mhayter commented Oct 20, 2024

I'm not really convinced this is an issue. If anything, the z algorithm article should be changed to have a similar line as the z algorithms is quite analogous to manacher's algorithm.

@adamant-pwn
Copy link
Member

It seems to get AC on Library Checker with this change. I don't remember why I put it there in the first place, so I will double-check and update the article if everything is really fine with it.

@adamant-pwn adamant-pwn self-assigned this Oct 30, 2024
@BYTE128
Copy link
Author

BYTE128 commented Nov 4, 2024

It seems to get AC on Library Checker with this change. I don't remember why I put it there in the first place, so I will double-check and update the article if everything is really fine with it.

I guess if "l" had been initialized with 0, then it could've lead to a negative index. As it is initialized with 1, we're saved. Correct me if I'm wrong though.

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

3 participants