Balanced Paranthesis Quiz question number 13

Following is an incorrect pseudocode for the algorithm which is supposed to determine whether a sequence of parentheses is balanced:

declare a character stack

while ( more input is available)

{
read a character

if ( the character is a ‘(’ )

  push it on the stack

else if ( the character is a ‘)’ and the stack is not empty )

  pop a character off the stack

else

  print "unbalanced" and exit

}
print “balanced”

Which of these unbalanced sequences does the above code think is balanced?

((())

())(()

(()()))

(()))()

hello @p8847220
i think u should try this on ur own.

just take each cases and follow the procedure they have mentioned.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.