Longest palindromic substring: Difference between revisions

Content deleted Content added
AnomieBOT (talk | contribs)
m Dating maintenance tags: {{Cn}}
Huyvvo (talk | contribs)
Line 110:
===Runtime===
 
The algorithm runs in linear time. This can be seen by puttingnoting boundsthat on<code>Center</code> howstrictly manyincreases iterations are run ofafter each loop. The outer loop and second inner loopthe incrementsum <code>Center</code> by+ <math>1</math> for every iteration. Since <code>CenterRadius</code> is boundednon-decreasing. byMoreover, the lengthnumber of theoperations string,in wethe knowfirst theseinner loopsloop runis <math>n</math>linear times.in the Theincrease firstof innerthe loop incrementssum <code>Center + Radius</code> bywhile <math>1</math>the fornumber everyof iterationoperations andin the second inner loop, whenis itlinear stops,in decrementsthe increase of <code>RadiusCenter</code>. bySince at<code>Center most 2n+1<math/code>1 and <code>Radius ≤ n</mathcode>, forthe everytotal iteration.number of Sinceoperations in the first and second inner looploops can run at mostis <math>O(n)</math> times and the valuetotal fornumber <code>Radius</code>of cannotoperations exceedin <math>n/2the outer loop,</math> theother firstthan innerthose loopin canthe runinner atloops, is mostalso <math>O(n + n/2)</math> times. The overall runtimerunning time is therefore <math>O\left(n + n + n/2\right) = O(n).</math>.
 
==Notes==