Computer Science
Consider the usual algorithm for determining whether a sequence of parentheses is balanced.
The maximum number of parentheses that appear on the Stack AT ANY ONE TIME when the algorithm analyzes: (()(())(())) is:
- 1
- 2
- 3
- 4 or more
Answer
3
Reason — Initially, two opening parentheses '(' are pushed onto the stack. When a closing parenthesis ')' is encountered, it is matched with an open parenthesis on the stack. Subsequently, two new opening parentheses are pushed onto the stack. Then subsequent two closing parentheses are matched with open parentheses on the stack and this process repeats. ensuring that at most, 3 parentheses are on the stack at any given time, maintaining balance.
Related Questions
Entries in a Stack are "ordered". What is the meaning of this statement?
- A collection of Stacks can be sorted.
- Stack entries may be compared with the '<' operation.
- The entries are stored in a linked list.
- There is a Sequential entry that is one by one.
Which of the following applications may use a Stack?
- A parentheses balancing program
- Tracking of local variables at run time
- Compiler Syntax Analyzer
- All of these
A linear list of elements in which deletion can be done from one end (front) and insertion can take place only at the other end (rear) is known as a:
- Queue
- Stack
- Tree
- Linked list
A Queue is a:
- FIFO (First In First Out) list
- LIFO (Last In First Out) list
- Ordered array
- Linear tree