You are designing an algorithm to match the opening and closing parentheses in an expression. Which data structure would be suitable for this purpose?

  • Array
  • Linked List
  • Queue
  • Stack
A stack is a suitable data structure for matching opening and closing parentheses in an expression. As you encounter opening parentheses, you push them onto the stack, and when you encounter a closing parenthesis, you pop from the stack, ensuring that they match. This approach helps maintain the order of parentheses and is well-suited for this purpose.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *