Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

You are to implement a Palindrome detector program. A palindrome is a series of

ID: 3559885 • Letter: Y

Question

You are to implement a Palindrome detector program. A palindrome is a series of intelligible characters that read the same both forward and backwards, excluding punctuation and spaces and normalizing case. The basic algorithm for this program will be:

1.   Remove all punctuation and spaces (work on a copy of the data, maintain the original).

2.   Change all characters to a single case (either upper or lower).

3.   Submit each character from the beginning of the string through the end of the string to both a stack and queue.

4.   Remove each character from both the stack and queue, comparing the output as they are removed.

5.   If the end of the stack and queue are reached and there are no mismatches, the string is a valid palindrome.

Legal Input will consist of a user entered sentence. Desired output will be whether or not the input sentence is a palindrome (yes, if it is, no, if it is not). An example of a valid palindrome is: "A man, a plan, a canal, Panama!" The letters amanaplanacanalpanama read the same both forward and backwards.

The output should include the original input, the printed output from the stack and queue, and lastly, the palindrome determination (yes or no).

Ensure the:

Explanation / Answer

What is Palindrome?

Palindrome is a pattern where irrespective of direction of access the semantics(meaning) remains same or in other way if the reverse of the Value or the String is same as theoriginal then the Value or the String is called Palindrome.


Example:
1881 - Reads "One Thousand Eight Hundred and Eighty One" from either side, so, it isPalindrome.

"MADAM" - Reads "MADAM" from either side, so, it is Palindrome.

198 - Reads "One Hundred and Ninety Eight" from left to right but reads "Eight Hundred and Ninety One" from right to left, so, it is Not Palindrome.

"MAD" - Reads "MAD" from left to right but reads "DAM" from right to left, so, it is Not Palindrome.

Problem Statement:

Design an algorithm to find a given Number N is Palindrome or Not.


Solution:

Algorithm Name: PalindromeNumber(N, R)

Input : N is any +ve integer greater than zero(0).

Output: R will be 0 if N is Not Palindrome Else R will be 1.

Step 1: X = N.

Step 2: Rev = 0.

Step 3: WHILE ( X != 0 )

           D = X % 10        [ MASK LSD ]

           X = Floor(X / 10) [ See Foot Note for Floor Function ]

           Rev = (Rev * 10) + D

        EndWhile

Step 4: IF ( Rev = N )

           R = 1

        ELSE

           R = 0

        EndIf

Step 5: Return.

Problem Statement:

Design an algorithm to find a given String is Palindrome or Not.


Solution:

Algorithm Name: PalindromeString(Str, R)

Input : Str is an character array containing alpha-numeric character set.

Output: R will be 0 if Str is Not Palindrome Else R will be 1.

Step 1: StrLen = StringLength(Str) [ Calculate the length of Str ]
Step 2: i = 0, j = (StrLen - 1)
Step 3: R = 1
Step 4: WHILE ( i < j )
           IF ( Str[i] != Str[j] )
              R = 0
              Return.
           EndIf
           i = i + 1
           j = j - 1
        EndWhile
Step 5: Return

NOTE:
1. Floor (X) is the largest integer not larger than X.
2. Ceiling (X) is the lowest integer not less than X.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote