×

Learn basic concept of c , c++ and python programming in regularcodes.com

# Check for Balanced Parentheses in an expression

Given a parenthesis ,check parentheses in an expression are balanced or not. few examples are given.

Example

**What a logic?**

Step 1: If any open Parenthesis are find then insert that parentheses to stack.

Step 2: if get close parenthesis then compared to stack Top element ASCII value are open expression. That means close parentheses are valid.then perform pop operation on stack.if not valid that means parentheses are not balanced.

View pointers and code execution process.

C program to check balanced parentheses in an expression. time complexity O(n).

**Output**

View comments and participate Discussion