Data Structures | Stack | Question 5
Following is an incorrect pseudocode for the algorithm which is supposed to determine whether a sequence of parentheses is balanced:
Which of these unbalanced sequences does the above code think is balanced?
Explanation: At the end of while loop, we must check whether the stack is empty or not. For input ((()), the stack doesn’t remain empty after the loop. See https://www.geeksforgeeks.org/check-for-balanced-parentheses-in-an-expression/ for details.