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.
Loading...
Related Quiz
- A ____ in Python is a collection of key-value pairs, where the keys must be immutable.
- What is the maximum length of an identifier (name of a variable, function, etc.) in Python?
- What would be the best data structure to implement a priority queue?
- A ____ is a special type of binary tree where each node has a higher (or equal) value than its children.
- Which type of tree would you use to implement an ordered map?