Question

In: Computer Science

Foundation of Computer Science A palindrome is a string that reads the same forward and backward....

Foundation of Computer Science

A palindrome is a string that reads the same forward and backward.

1. Describe an algorithm that determines whether a string of n characters is a palindrome.

2. Write its corresponding program using your favorite programming language.

Solutions

Expert Solution

Algorithm

Step1-Start

Step2-Input a string and store it in a variable (eg-ostring)

Step3- Reverse the string and store it in another variable (eg-rstring)

Step4-Compare the original string and reversed string(ie ostring and rstring), If both are equal return true(string is pallindrome) else return false(string is not pallindrome)

Step5-Stop

Program(Python Language)

def check_pal(ostring): #pallindrome function with argument ostring which is input string

rstring="" #variable rstring(for storing reverse string) with empty string initialized

for l in ostring: #loop through input string character by character

rstring=l+rstring #add the characters to rstring from right to left(ie in reverse)

if(rstring==ostring): #compare input string and reverse string

print("String is a pallindrome ") #if true it is a pallindrome

else: #if input string not equal to reverse(ie false)

print("String is not a pallindrome") #print it is not a pallindrome

while(1): #keep program repeating till user want

ostring=input("Enter a string:") #input string and store in ostring variable

check_pal(ostring)

#call the function with input as argument to check if string is pallindrome


#please use tab for indentation as python language is used(as given in the image)

Output


Related Solutions

C++: A palindrome is a string that is the same backward as it is forward. For...
C++: A palindrome is a string that is the same backward as it is forward. For example, “tot” and “otto” are rather short palindromes. Write a program that lets a user enter a string and that passes to a bool function a reference to the string. The function should return true if the string is a palindrome and false otherwise. When you do the judgment, capitalization, spaces, and punctuation should be neglected, that is, “Madam, I’m Adam” should test as...
A palindrome is a word or phrase, which reads the same backward or forward. Write a...
A palindrome is a word or phrase, which reads the same backward or forward. Write a program that prompts the user for a string of characters terminated by a period and determines whether the string (without the period) is a palindrome. IMP: Assume that the input contains only letters and blanks. Assume also that the input is at most 30 characters long. Use an array of characters of size 30 to store the input! Disregard blanks when deciding if the...
In C++: This is the problem: [(1)] A palindrome is a string that reads the same...
In C++: This is the problem: [(1)] A palindrome is a string that reads the same forwards as backwards. Using only a fixed number of stacks and queues, the stack and queue ADT functions, and a fixed number of int and char variables, write an algorithm to determine if a string is a palindrome. Assume that the string is read from standard input one character at a time. The algorithm should output true or false as appropriate [(2)] Let Q...
A palindrome is a word or a phrase that is the same when read both forward and backward.
6.7 LAB: PalindromeA palindrome is a word or a phrase that is the same when read both forward and backward. Examples are: "bob," "sees," or "never odd or even" (ignoring spaces). Write a program whose input is a word or phrase, and that outputs whether the input is a palindrome.Ex: If the input is:bobthe output is:bob is a palindromeEx: If the input is:bobbythe output is:bobby is not a palindromeHint: Start by removing spaces. Then check if a string is equivalent to it's reverse.This is my code:s =...
IN JAVA - [(1)] A palindrome is a string that reads the same forwards as backwards....
IN JAVA - [(1)] A palindrome is a string that reads the same forwards as backwards. Using only a fixed number of stacks and queues, the stack and queue ADT functions, and a fixed number of int and char variables, write an algorithm to determine if a string is a palindrome. Assume that the string is read from standard input one character at a time. The algorithm should output true or false as appropriate [(2)] Let Q be a non-empty...
JAVA. A palindrome is a word or a phrase that is the same when read both forward and backward.
java please. A palindrome is a word or a phrase that is the same when read both forward and backward. Examples are: "bob," "sees," or "never odd or even" (ignoring spaces). Write a program whose input is a word or phrase, and that outputs whether the input is a palindrome.Ex: If the input is:bobthe output is:bob is a palindromeEx: If the input is:bobbythe output is:bobby is not a palindromeHint: Start by removing spaces. Then check if a string is equivalent to it's reverse.Hint: Start by just handling single-word...
(Palindrome number - A number is a palindrome if it reads the same from right to...
(Palindrome number - A number is a palindrome if it reads the same from right to left and from left to right, for example 676 is a palindrome number) Write a program that prompts the user to enter a three-digit integer number and determines whether it is a palindrome number or not In Java Please
1. A is called a palindrome if it reads the same from left and right. For...
1. A is called a palindrome if it reads the same from left and right. For instance, 13631 is a palindrome, while 435734 is not. A 6-digit number n is randomly chosen. Find the probability of the event that (a) n is a palindrome. (b) n is odd and a palindrome. (c) n is even and a palindrome.
A is called a palindrome if it reads the same from left and right. For instance,...
A is called a palindrome if it reads the same from left and right. For instance, 13631 is a palindrome, while 435734 is not. A 6-digit number n is randomly chosen. Find the probability of the event that (a) n is a palindrome. (b) n is odd and a palindrome. (c) n is even and a palindrome.
making a python code for this: A palindrome is a sequence that reads the same backwards...
making a python code for this: A palindrome is a sequence that reads the same backwards as forwards. Numbers can also be palindromes if we consider their digits as a sequence, for example 12121 and 8228 are palindromes. We can find palindromes from an initial seed number using the reverse and add method: choose a number, reverse its digits and add it to the original. If the sum is not a palindrome (which means, it is not the same number...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT