1.

Consider the usual algorithm for determining whether a sequence of parentheses is balanced. Suppose that you run the algorithm on a sequence that contains 2 left parentheses and 3 right parentheses (in some order). The maximum number of parentheses that appear on the stack AT ANY ONE TIME during the computation?(a) 1(b) 2(c) 3(d) 4Please solve the problem as soon as possible.

Answer»

Correct answer is (B) 2

Easy explanation - In the entire parenthesis balancing method when the INCOMING token is a left parenthesis it is pushed into stack. A right parenthesis makes POP operation to DELETE the elements in stack till we get left parenthesis as top most element. 2 left parenthesis are pushed whereas ONE right parenthesis removes one of left parenthesis. 2 elements are there before right parenthesis which is the maximum number of elements in stack at run time.



Discussion

No Comment Found

Related InterviewSolutions