Question

In: Computer Science

A palindrome is a string of characters (a word, phrase, or sentence) that is the same...

A palindrome is a string of characters (a word, phrase, or sentence) that is the same regardless of whether you read it forward or backward – assuming that you ignore spaces, punctuation and case. For example, Race car is a palindrome. So is A man, a plan, a canal: Panama.

1. Describe how you could use a stack to test whether a string is a palindrome.

2. Describe how you could use a queue to test whether a string is a palindrome.

Solutions

Expert Solution

Algorithms for both the cases are given below:

1. Algorithm to check palindrome string using stack

  • Find the length of the input string using strlen function and store it in an integer variable "length".
  • Using a for loop, traverse input string from index 0 to (length-1) and push all characters in stack.
  • Remove (Pop) characters from stack one by one using a for loop and compare it with the corresponding character of input string from the beginning(traverse from index 0 to length-1). If we found a mismatch the input string is not a palindrome string otherwise palindrome string.

2. Algorithm to check palindrome string using queue

  • Find the length of the input string "input_string" using strlen function and store it in an integer variable "length".
  • Using a for loop, traverse input string from index (length-1) to 0 and push all characters in the queue.
  • Remove (Pop) characters from queue one by one using a for loop and store them in a new string variable "reverse_string".
  • Compare the variables "input_string" with "reverse_string" from the beginning (traverse from index 0 to length-1). If we found a mismatch the input string is not a palindrome string otherwise it is palindrome string.

Related Solutions

A palindrome is a word or a phrase that is the same when read both forward...
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: bob the output is: bob is a palindrome Ex: If the input is: bobby the output is: bobby is not a palindrome Hint: Start by just handling...
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 =...
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...
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...
4. (20 marks) A English word is palindrome if its characters read the same backward as...
4. A English word is palindrome if its characters read the same backward as forward. For example, civic is palindrome. Describe a recursive algorithm for determining a word w of length n is palindrome or not. Analyze its time complexity using a recursion tree. Implement your algorithm in Java
Create using Java Description: Palindrome -- According to wikipedia "A palindrome is a word, phrase, number...
Create using Java Description: Palindrome -- According to wikipedia "A palindrome is a word, phrase, number or other sequence of units that can be read the same way in either direction" Write a application that can determine if a 5 digit number you input is a palindrome. If the number is a palindrome then print "The number is a palindrome." If it is not then print "The number is NOT a palindrome" Make sure to use an array Allow input...
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...
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...
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...
A palindrome is a string that reads the same forward and backward, i.e., the letters are...
A palindrome is a string that reads the same forward and backward, i.e., the letters are the same whether you read them from right to left or from left to right.      Examples: radar à is a palindrome Able was I ere I saw Elba à is a palindrome good à not a palindrome Write a java program to read a line of text and tell if the line is a palindrome. Use a stack to read each non-blank character...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT