Actually complexity is O(n), BUT it won't work for aaaaaa. It'll
return "aa" instead of the whole string.
I think you can use similar approach but add another check under the
first 'if' statement since 'aaaaaa'
is a special case. But then again the algo will crap out for a string=
aaaabbaaaa. I think the best way would
be to start with from the middle and span outwards. this way you
should find the longest even palindrome of
even length.

On Jun 5, 6:52 am, Bharath <[email protected]> wrote:
> Complexity is O(n3) for both above solutions
>
> Ex: aaaaaaaa
>
>
>
>
>
> On Sat, Jun 5, 2010 at 3:27 AM, Minotauraus <[email protected]> wrote:
> > for(int i=0; i<word.length-1; i++)
> > {
> >  if(word[i]==word[i+1]) //for an even palindrome, consecutive letters
> > at the middle of the string have to be the same
> >       {
> >           palindromeFound=true;
>
> >           while(n>0&&m<word.length) //once you've found the middle of
> > the palindrome, compare left of and right of, while making sure you
> > don't go out of                         bounds
> >            {
> >                 if(word[n--]==word[m++])
> >                      {
> >                         startIndex = n; //overwrite index of the
> > start and end locations
> >                         endIndex = m;
>
> >                      }
> >                     else break;
> >            }
> >       }
> > }
>
> > print("Even length-ed Palindrome: "+word[startIndex->endIndex], length
> > = endIndex-startIndex);
>
> > Complexity =O(n).
>
> > On Jun 5, 2:34 am, Satya <[email protected]> wrote:
> > > Hi,
>
> > > How to find largest palindrome, which is even in length in a string.
> > > Complexity should be "lessthan" O(n^2).
>
> > > Ex;- abacbbcababac - Given string.
> > > 'abacbbcaba' - is the largest even length palindrome.
>
> > > Thanks,
> > > Satya
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Algorithm Geeks" group.
> > To post to this group, send email to [email protected].
> > To unsubscribe from this group, send email to
> > [email protected]<algogeeks%2bunsubscr...@googlegroups 
> > .com>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/algogeeks?hl=en.
>
> --
> <<Bharath>>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to