• RSS
  • Facebook
  • Twitter

Knowledge is Power.

  • Who you are ?

    Working on machines without understanding them ? Then you should be here..

  • Where you are ?

    Geographical location should not become a barrier to Share our knowledge.

  • What do you do ?

    Puzzles and Interview question are intended to be discussed here.

    Thursday, February 25, 2010

    The list shows above is a palindrome and we need to check if it is indeed a palindrome. Among several approaches, the following is a simple and easy to understand method.

    Algorithm:
    1. Get the middle of the linked list.
    2. Reverse the second half of the linked list.
    3. Compare the first half and second half.
    4. Construct the original linked list by reversing the
    second half again and attaching it back to the first half

    Time Complexity O(n)
    Space Complexity O(1)

    0 comments:

    Post a Comment