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

Palindromes are character sequences that read the same forward or backwards (e.g

ID: 3725404 • Letter: P

Question

Palindromes are character sequences that read the same forward or backwards (e.g. the strings "mom" or "123 454 321"). Punctuation and spaces are frequently ignored so that phrases like "Dog, as a devil deified, lived as a god." are palindromes. Conversely, even if spaces are not ignored phrases like "Rats live on no evil star" are still palindromes.

Specifications

Design

1) Create a flowchart or use pseudocode to indicate how the recursion will determine if a given string is a palindrome. Don’t forget the rules for creating a good recursive function.

2) Create a flowchart of use pseudocode to indicate how to get values from the list of command line parameters and determine whether you have a flag and dealing with those as well.

3) Determine test cases that will never be a palindrome, always be a palindrome, as well as cases where its status as a palindrome depends on the flags.

Explanation / Answer

//recurrence function to find palindrome or not
//this function will take string and start, end index of the string
//as parameters
isPalindrome(str,start,end)
   //if space at start index,then increment
   if str[start] equals to space
       increment start
   //if space at end index, then decrement
   if str[end] equals to space
       decrement end
   //if length of string is 1
   if start is equals to end
       return true
   //even at one index not matches, its not palindrome
   //so,return as false
   if str[start] not equals to str[end]
       return false
   //if there is substring
   //check palindrome for that sub string
   if start < end+1
       return isPalindrome(str,start+1,end-1)
  
//main function
main()
   str[]<-ask for string//prompt for user
   length<-find length//find length
   if length equals to 0
       print "Zero length"
   else
       if(isPalindrome(str,0,length-1))
           print "Palindrome"
       else
           print "Not palindrome"