Skip to content
DATA STRUCTURE
DATA STRUCTURE

Learn everything about Data structure

  • Algorithms
  • DSA
  • Array
  • Stack
  • Queue
  • Matrix
  • Programs
DATA STRUCTURE

Learn everything about Data structure

Parenthesis matching using stack

YASH PAL, January 26, 2023May 28, 2024

Parenthesis matching algorithm

PARENTHESIS_MATCHING (EQ, VALID)
This algorithm checks whether the expression EQ written in infix notation is valid or not and assigns TRUE or FALSE to VALID.

[br]

1. Scan EQ from left to right until the end of the equation is encountered:
2.     If”(“is encountered then: put it in the STACK.
3.     If the closing bracket is encountered then:
              (a) If STACK is empty, then Set VALID: = FALSE and return.
              (b) Pop the “(” from the STACK.
        [End of If structure.]
    [End of Step 2 loop.]
4. If STACK is empty, then:
       Set VALID := TRUE
7. Else:
      Set VALID := FALSE

    [End of If structure.]

8. Return

[br]

data structures stack DSAstack

Post navigation

Previous post
Next post
  • HackerRank Dynamic Array Solution in Python
  • HackerRank 2D Array DS solution in Python
  • HackeRank Array – DS solution in Python
  • Streaming Demystified: How Much Data Does Your Favorite Show Really Use?
  • Parenthesis Matching program in C programming
  • HackerRank Dynamic Array Solution in Python
  • HackerRank 2D Array DS solution in Python
  • HackeRank Array – DS solution in Python
  • Streaming Demystified: How Much Data Does Your Favorite Show Really Use?
  • Parenthesis Matching program in C programming
  • About US
  • Contact US
  • Data Structures and algorithms tutorials
  • Digital Communication Tutorials
  • DMCA
  • HackerRank All Algorithms problems solutions
  • HackerRank C problems solutions
  • HackerRank C++ problems solutions
  • HackerRank Java solutions
  • HackerRank Python solutions
  • Human Values Tutorials
  • Internet of Things Tutorials
  • Privacy Policy
©2025 DATA STRUCTURE | WordPress Theme by SuperbThemes