Longest palindromic substring: Difference between revisions

Content deleted Content added
Copy editing.
m Copy editing.
Line 110:
===Runtime===
 
The algorithm runs in linear time. This can be seen by putting bounds on how many iterations are run of each loop. The outer loop and second inner loop increment <code>Center</code> by <math>1</math> for every iteration. Since <code>Center</code> is bounded by the length of the string, we know these loops run <math>n</math> times. The first inner loop increments <code>Radius</code> by <math>1</math> for every iteration and the second inner loop, when it stops, decrements <code>Radius</code> by at most <math>1</math> for every iteration. Since the second inner loop can run at most <math>n</math> times and the value for <code>Radius</code> cannot exceed <math>n/2,</math>, the first inner loop can run at most <math>n + n/2</math> times. The overall runtime is <math>O\left(n + n + n/2\right) = O(n).</math>.
 
==Notes==