UGC-NET Jun 2014 · Stacks

MCQ · 2 marks · Problem PROG-DSTR-0043

What is the maximum number of parenthesis that will appear on the stack at any one time for parenthesis expression given by $( ( )     \;     ( ( ) ) \;           ( ( ) ) )$
  1. A
    $2$
  2. B
    $3$
  3. C
    $4$
  4. D
    $5$

Solve it on GATE DA practice →More Basic Data Structures problems

Show the worked solutionPush on '(' and pop on ')'. Stack size after each symbol of \((\,(\,)\,(\,(\,)\,)\,(\,(\,)\,)\,)\):\[1,\ 2,\ 1,\ 2,\ 3,\ 2,\ 1,\ 2,\ 3,\ 2,\ 1,\ 0.\]The maximum, reached inside each inner \((\,(\,)\,)\) group, is 3, which is the nesting depth.Answer: B

GATE DA practice: past exam problems by chapter, with worked solutions · gatedaprep.com