Question
JAVA DATA STRUCTURES Here is an incorrect pseudo code for an algorithm which is supposed to determine whetehr a String of paranthesses is balanced: boolean
JAVA DATA STRUCTURES
"Here is an incorrect pseudo code for an algorithm which is supposed to determine whetehr a String of paranthesses is balanced:"
boolean isBalanced(String input)
{
declare a character stack
while ( input has more characters)
{
read a character from input
if ( the character is a ' ( ' )
push it on the stack
else if ( the stack is not empty )
pop a character off the stack
else
return false
}
return true
}
"Give an example of an input string that is made up of only the characters ' ( ' and ' ) ' , is unbalanced, but for which this algorithm will return true. Explain what is wrong with the algorithm. Can this algorithm ever incorrectly return false when its input string is balanced string?"
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started