Question

Write an algorithm not code or solution only algorithm such as (step1, step2.....about. 1.How would you...

Write an algorithm not code or solution only algorithm such as (step1, step2.....about.

1.How would you use a stack to verify whether a given string is a palindrome or not.

2. How would you check if a string is a palindrome or not, using queues and deques.

Homework Answers

Answer #1

1. Algorithm:

Step 1: Start

Step 2: Store each character of input string in the stack, character by character. Element that is at the end of the string will be accessed first.

Step 3: Iterate over the Input string from first character and match it with the top character of the stack. If the element matches then remove it and move to the next character.

Step 4: If all the characters match and you are left with an empty stack then it's a pallindrome else it's not.

Step 5: Stop

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Java Please [(1)] A palindrome is a string that reads the same forwards as backwards. Using...
Java Please [(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 queue,...
Using c++ Valid Palindrome In this assignment, you need to implement a bool isPalindrome(string s) function....
Using c++ Valid Palindrome In this assignment, you need to implement a bool isPalindrome(string s) function. Given a string s, isPalindrome(s) can determine if s is a palindrome, considering only alphanumeric characters and ignoring cases. Note: for the purpose of this problem, we define empty string as valid palindrome. Example 1: Input: ”A man, a plan, a canal: Panama” Output: true Example 2: Input: ”race a car” Output: false Requirement: There are many methods to check if a string is...
Write the below code to use HTML and JavaScript. 1)Write a JavaScript program to create a...
Write the below code to use HTML and JavaScript. 1)Write a JavaScript program to create a new string from a given string changing the position of first and last characters. The string length must be greater than or equal to 1. 2)Write a JavaScript program to check whether a string starts with 'Java' and false otherwise
Write a program that determines whether an input string a palindrome; that is whether it can...
Write a program that determines whether an input string a palindrome; that is whether it can be read the same way forward and backward. At each point, you can read only one character of the input string; do not use an array to first store this string and then analyze it (except, possibly in a stack implementation). Consider using multiple stacks. PLEASE PROVIDE A PSEUDOCODE
Demonstrate your continuous progress in learning MIPS assembly by writing and executing the program below. Edit...
Demonstrate your continuous progress in learning MIPS assembly by writing and executing the program below. Edit the program using your favorite code editor (e.g. Notepad++) and load the programs into QtSpim for execution. Activity Directions: Write a program that will read a line of text and determine whether or not the text is a palindrome. A palindrome is a word or sentence that spells exactly the same thing both forward and backward. For example, the string “anna” is a palindrome,...
Queues, Lists, and Stacks Assignment: Write client methods to do the following Assume that there exists...
Queues, Lists, and Stacks Assignment: Write client methods to do the following Assume that there exists in main a list   declared as : List<Integer> aList   =   new   List<Integer>(50); Write a client method called bubbleSort which given a list as a parameter uses the bubble sort algorithm to sort the contents of the list. YOU MAY ASSUME that there exists a method called swap (with the following signature) which swaps the contents of two elements: // swap public static void swap(List<Integer>...
I am having some trouble writing some java code involving strings. I have included the code...
I am having some trouble writing some java code involving strings. I have included the code provided by my professor below. that has the instructions in it as well public class StringExercise { public static void main(String[] args) { String given = "The quick brown fox jumped over the moon!"; String given2 = "mary"; String given3 = "D"; //Write a Java code snippet to check (print a boolean) whether the given String ends with the contents of "oon!", see endsWith...
IN JAVA One possible application of a Stack is to check for balanced parentheses or braces...
IN JAVA One possible application of a Stack is to check for balanced parentheses or braces in an expression. An expression is considered to be balanced if:  There are an equal number of open and close parantheses; AND  Every closed parenthesis seen (when parsing the expression from left to right) must be paired with a previously seen open parenthesis. Write an algorithm (not code, an algorithm) for how you would use a stack to check for balanced parentheses....
(a) Write an algorithm (use pseudo-code) to determine whether a function f ∶ Z100 → Z100...
(a) Write an algorithm (use pseudo-code) to determine whether a function f ∶ Z100 → Z100 is surjective. That is, supply a “Method” to go with Input: A function (array) f with f(i) ∈ Z100 for i = 0, 1, . . . , 99. Output: Boolean B. B=‘true’ if f is surjective, ‘false’ otherwise. Try to make your algorithm as efficient as possible. Do NOT include an implementation of your algorithm in a programming language. (b) How many comparisons...
In 1-3 sentences, describe how you would make a "Function that can test if an arbitrary...
In 1-3 sentences, describe how you would make a "Function that can test if an arbitrary string is a palindrome if stripped of punctuation", Recursively using C++
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT