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

A palindrome is a word that is spelled the same forward and backward. Write a re

ID: 3634115 • Letter: A

Question

A palindrome is a word that is spelled the same forward and backward.
Write a recursive function named isPalindrome(<string>) that determines if an input string is a palindrome. If the input <string> is a palindrome, then isPalindrome(<string>) should return a logical true. If the input <string> is NOT a palindrome, then isPalindrome(<string>) should return a logical false. Think carefully about what the termination conditions should be and how many base cases will be required.
HINTS: What should happen when a string only has a single character? Is it necessary to complete the examination of an input string once a mismatch is discovered?

For example:
isPalindrome('rotator') should return true
isPalindrome('radar') should return true
isPalindrome('bob') should return true
isPalindrome('palindrome') should return false

A logical true value can be returned from a function in two ways:
result = logical(1);
or
result = true;

A logical false value can be returned from a function in two ways:
result = logical(0);
or
result = false;


Explanation / Answer

function result = isPalindrome(string) size = length(string); if length(string) == 1 || isempty(string) result = 'true'; elseif string(1) == string(size) string(1) = []; string(size-1) = []; result = isPalindrom(string); else result = 'false'; end end

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