A string is said to be a palindrome when the string read from left to right is equal to the string read from right to left, ignoring the differences between uppercase and lowercase characters.
Example: Madam, Level, Radar, etc.
In simple words, a string is said to be palindrome when the string read backwards is equal to the given string or when both the string and its reverse are equal.
Now let’s take a look at the algorithm and flowchart to check whether a given string is palindrome or not, for better understanding.
We are starting the algorithm by taking the string to be checked as input from the user. After that, the length of the string is calculated and stored in a variable, say ‘length’. To check whether a string is palindrome or not, the given string must be reversed. To store the reversed string, we are initializing a variable ‘rev’ as an empty string. That being done, we are starting a loop with initial value i = length – 1. In this loop, we are reversing the string, one character at a time by performing: rev = rev + character at position i. Here, the ‘+’ operator performs the concatenation of the characters of the string in reverse order. After that, the value of ‘i’ is decremented by 1. This loop runs until i >= 0. Once this loop ends, we have the reversed string in the variable rev.
We will now check whether both the strings are equal or not, ignoring the cases of the characters. If both the strings are equal, the given string is palindrome, else, the given string is not palindrome.