Be the first user to complete this post

  • 0
Add to List
Beginner

7. Determine If a String is Palindrome

Objective : Write an algorithm to find Whether Given String is palindrome or Not.

Input:  String
Output: true or false on whether string is palindrome or not

Approach:

  • Use recursive approach
  • Compare first and last characters if they are not same- return false
  • If they are same make, remove the first and last characters and make a recursive call. 

Example:

ABCD DCBA -  compare A with A, returns true

BCD DCB, compare B with B, returns true

CD CD, compare C with C, returns true

D D, compare D with D, returns true

string length <2 => returns true
Is ABCDA Palindrome: false
Is SumuS Palindrome: true
Is ABCDEFGHGFEDCBA Palindrome: true