Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 92d51cb

Browse files
roll-no-1jakobkogler
authored andcommitted
Changed article name and a code segment (#417)
1 parent 5f5f943 commit 92d51cb

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ and adding new articles to the collection.*
8282
- [Lyndon factorization](./string/lyndon_factorization.html)
8383
- **Tasks**
8484
- [Expression parsing](./string/expression_parsing.html)
85-
- [Finding all sub-palindromes in O(N)](./string/manacher.html)
85+
- [Manacher's Algorithm - Finding all sub-palindromes in O(N)](./string/manacher.html)
8686
- [Finding repetitions](./string/main_lorentz.html)
8787

8888
### Linear Algebra

src/string/manacher.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
<!--?title Finding all sub-palindromes in O(N)-->
1+
<!--?title Manacher's Algorithm - Finding all sub-palindromes in O(N)-->
22

3-
# Finding all sub-palindromes in $O(N)$
3+
# Manacher's Algorithm - Finding all sub-palindromes in $O(N)$
44

55
## Statement
66

@@ -87,7 +87,7 @@ So, we want to calculate $d_1[i]$ for the next $i$, and all the previous values
8787
8888
But there is a **tricky case** to be handled correctly: when the "inner" palindrome reaches the borders of the "outer" one, i. e. $j - d_1[j] + 1 \le l$ (or, which is the same, $i + d_1[j] - 1 \ge r$). Because the symmetry outside the "outer" palindrome is not guaranteed, just assigning $d_1[i] = d_1[j]$ will be incorrect: we have not enough data to state that the palindrome in the position $i$ has the same length.
8989
90-
Actually, we should "cut" the length of our palindrome, i. e. assign $d_1[i] = r - i$, to handle such situations correctly. After this we'll run the trivial algorithm which will try to increase $d_1[i]$ while it's possible.
90+
Actually, we should "cut" the length of our palindrome, i. e. assign $d_1[i] = r - i + 1$, to handle such situations correctly. After this we'll run the trivial algorithm which will try to increase $d_1[i]$ while it's possible.
9191
9292
Illustration of this case (the palindrome with center $j$ is already "cut" to fit the "outer" palindrome):
9393
@@ -130,7 +130,7 @@ For calculating $d_1[]$, we get the following code:
130130
```cpp
131131
vector<int> d1(n);
132132
for (int i = 0, l = 0, r = -1; i < n; i++) {
133-
int k = (i > r) ? 1 : min(d1[l + r - i], r - i);
133+
int k = (i > r) ? 1 : min(d1[l + r - i], r - i + 1);
134134
while (0 <= i - k && i + k < n && s[i - k] == s[i + k]) {
135135
k++;
136136
}

0 commit comments

Comments
 (0)