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%[email protected]> > . > 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.
