Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7997945
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T15:05:44+00:00 2026-06-04T15:05:44+00:00

I was Googling about a rather well-known problem, namely: the longest palindromic substring I

  • 0

I was Googling about a rather well-known problem, namely: the longest palindromic substring
I have found links that recommend suffix tries as a good solution to the problem.
Example SO and Algos
The approach is (as I understand it) e.g. for a string S create Sr (which is S reversed) and then create a generalized suffix trie.
Then find the longest common sustring of S and Sr which is the path from the root to the deepest node that belongs both to S and Sr.
So the solution using the suffix tries approach essentially reduces to Find the longest common substring problem.
My question is the following:
If the input string is: S = “abacdfgdcaba” so , Sr = “abacdgfdcaba” the longest common substring is abacd which is NOT a palindrome.
So my question is: Is the approach of using suffix tries erroneous? Am i missunderstanding/misreading here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T15:05:46+00:00Added an answer on June 4, 2026 at 3:05 pm

    Yes, finding longest palindrome by using LCS like algorithms is not a good way, I didn’t read referenced answer carefully but this line in the answer is completely wrong:

    So the longest contained palindrome within a string is exactly the longest common substring of this string and its reverse

    but if you read it and you have a counter example don’t worry about it (you are right in 99%), this is common mistake, But simple way is as follow:

    Write down the string (barbapapa) as follow: #b#a#r#b#a#p#a#p#a#, now traverse each character of this new string from left to right, check its left and right to check whether it’s a palindrome center or not. This algorithm is O(n^2) in worst case and works perfectly correct. but normally will finds palindrome in O(n) (sure proving this in average case is hard). Worst case is in strings with too many long palindromes like aaaaaa...aaaa.

    But there is better approach which takes O(n) time, base of this algorithm is by Manacher. Related algorithm is more complicated than what I saw in your referenced answer. But what I offered is base idea of Manacher algorithm, with clever changes in algorithm you can skip checking all left and rights (also there are algorithms by using suffix trees).


    P.S: I couldn’t see your Algo link because of my internet limitations, I don’t know it’s correct or not.

    I added my discussion with OP to clarify the algorithm:

    let test it with barbapapa-> #b#a#r#b#a#p#a#p#a#, start from first #
    there is no left so it's center of palindrome with length 1.
    Now "b",has # in left and # in right, but there isn't another left to match with right 
    so it's a center of palindrome with length 3.
    let skip other parts to arrive to first "p":
    first left and right is # second left and right is "a", third left and
    right is # but forth left and right are not equal so it's center of palindrome
    of length 7 #a#p#a# is palindrome but b#a#p#a#p is not 
    Now let see first "a" after first "p" you have, #a#p#a#p#a# as palindrome and this "a" 
    is center of this palindrome with length 11 if you calculate all other palindromes 
    length of all of them are smaller than 11
    

    Also using # is because considering palindromes of even length.

    After finding center of palindrome in newly created string, find related palindrom (by knowing the center and its length), then remove # to find out biggest palindrome.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Googling this does little good, as you can imagine. Does anyone have resources that
While googling I found two different sets of headers that need to be set
I have been googling about this issue for hours, and I'm stumped. Im trying
I have some questions about cakePHP, I spent long time Googling for a solution
I have encountered a rather odd error that I do not understand. I created
I have been googling for about 90 minutes now and still don't have an
Googling I've found this article: http://java.dzone.com/tips/generating-client-java-code It talk about how to generate a JAVA
Googling today I couldn't found sample or mentioning of best practice: how to escape
After googling i came to know that Index seek is better than scan. How
I have a couple of sqlite dbs (i'd say about 15GBs), with about 1m

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.