Skip to content
TestMacher
Chapter 7 · Class 12 Computer Science

Stacks — Important Questions

31 questions With answers CBSE format

SUMMARY: The chapter on Stacks in Class 12 Computer Science covers the concept, implementation, and applications of stack data structures.
KEY TOPICS: stack definition, LIFO principle, stack operations, stack implementation using arrays, stack implementation using linked lists, applications of stacks, recursion and stacks, infix to postfix conversion, evaluation of postfix expressions, stack overflow and underflow.

Q1 1 Mark

Which of the following best describes a stack data structure?

AFIFO
BLIFO
CRandom access
DPriority based
Check answerHide answer
Correct answer: Option 2 — LIFO
Q2 1 Mark

Which operation is used to add an element to a stack?

Apush
Bpop
Cpeek
Denqueue
Check answerHide answer
Correct answer: Option 1 — push
Q3 1 Mark

Which operation is used to remove the top element of a stack?

Apush
Bpop
Cenqueue
Ddequeue
Check answerHide answer
Correct answer: Option 2 — pop
Q4 1 Mark

A stack overflow occurs when:

AStack is empty and pop is called
BStack is full and push is called
CStack has one element
DStack has integer elements
Check answerHide answer
Correct answer: Option 2 — Stack is full and push is called
Q5 1 Mark

Which Python data type is most commonly used to implement a stack?

ATuple
BSet
CList
DDictionary
Check answerHide answer
Correct answer: Option 3 — List
Q6 3 Marks

Define stack and explain its LIFO principle.

Q7 3 Marks

List any three real-life applications of stacks.

Q8 3 Marks

Differentiate between stack and queue with two points.

Q9 3 Marks

Write a Python function to push an element onto a stack implemented as a list.

Q10 3 Marks

Explain when a stack overflow and a stack underflow occur.

Q11 6 Marks

Write a Python program to implement a stack using a list. Include push pop peek and isEmpty operations.

Q12 6 Marks

Discuss any five applications of stacks in computer science.

Q13 6 Marks

Write a Python program using a stack to check if a given string of brackets is balanced.

Q14 6 Marks

Explain how the call stack works during function execution especially with recursion.

Q15 6 Marks

Write a Python program using a stack to reverse a string.

Q16 6 Marks

Differentiate between stack and queue data structures in tabular form on five features.

Q17 1 Mark

Assertion (A): Stack follows the LIFO principle.

Reason (R): The last element pushed is the first one popped.

Show explanationHide explanation
Correct answer: Option 1 — Both A and R are true, and R is the correct explanation of A.
Q18 1 Mark

Assertion (A): Function calls in most languages use a stack.

Reason (R): The call stack tracks the order of function calls and returns.

Show explanationHide explanation
Correct answer: Option 1 — Both A and R are true, and R is the correct explanation of A.
Q19 1 Mark

Assertion (A): The peek operation returns the top element without removing it.

Reason (R): It does not modify the stack.

Show explanationHide explanation
Correct answer: Option 1 — Both A and R are true, and R is the correct explanation of A.
Q20 1 Mark

Assertion (A): Stack overflow happens when the stack reaches its maximum capacity.

Reason (R): Pushing more elements is not allowed in a fixed-size stack.

Show explanationHide explanation
Correct answer: Option 1 — Both A and R are true, and R is the correct explanation of A.
Q21 1 Mark

Assertion (A): The undo feature in many applications uses a stack.

Reason (R): Each action is pushed and the undo command pops the last action.

Show explanationHide explanation
Correct answer: Option 1 — Both A and R are true, and R is the correct explanation of A.
Q22 1 Mark

Statement 1: A stack has only one entry/exit point called the top.

Statement 2: All operations are performed at the top.

Show answerHide answer
Correct answer: Option 1 — Both statements are true.
Q23 1 Mark

Statement 1: Push and pop are the two basic stack operations.

Statement 2: Both operate on the top of the stack.

Show answerHide answer
Correct answer: Option 1 — Both statements are true.
Q24 1 Mark

Statement 1: Stack can be implemented using arrays or linked lists.

Statement 2: In Python list operations append() and pop() implement push and pop.

Show answerHide answer
Correct answer: Option 1 — Both statements are true.
Q25 1 Mark

Statement 1: Stacks are used in expression evaluation.

Statement 2: Infix to postfix conversion uses a stack.

Show answerHide answer
Correct answer: Option 1 — Both statements are true.
Q26 1 Mark

Statement 1: Browser back button uses a stack.

Statement 2: Each visited page is pushed; back pops the most recent one.

Show answerHide answer
Correct answer: Option 1 — Both statements are true.
Q27 3 Marks
A student is asked to write a Python program that takes a string of brackets like ([ {} ]) and checks if all brackets are balanced. She decides to use a stack — push opening brackets and pop when a closing bracket matches. If the stack is empty at the end the brackets are balanced.
  1. A stack uses which principle?
    AFIFO
    BLIFO
    CRandom access
    DPriority
  2. Which operation removes the top element of a stack?
    Apush
    Bpop
    Cpeek
    Denqueue
  3. Write the Python program using a stack to check balanced brackets.
Show answersHide answers
1. Option 2 — LIFO
2. Option 2 — pop
3. def is_balanced(s): stack = []; pairs = {')':'(' ']':'[' '}':'{'}; for ch in s: if ch in '([{': stack.append(ch); elif ch in ')]}': if not stack or stack.pop() != pairs[ch]: return False; return len(stack) == 0. Push opening brackets; on each closing bracket check that the top of stack matches. After processing if the stack is empty the brackets are balanced.
Q28 5 Marks

Trace the stack contents after each operation (push or pop).

OperationStack after
push 10?
push 20?
push 30?
pop?
push 40?
pop?
Q29 6 Marks

Trace the stack to evaluate balanced bracket check on the string '([{}])'.

Char readActionStack after
(push[(]
[push[(, []
{push[(, [, {]
}??
]??
)??
Q30 3 Marks

Study the operations on a stack and answer:

OperationEffectTime complexity
push(x)Add x at topO(1)
pop()Remove top, returnO(1)
peek()/top()Return top, no removeO(1)
isEmpty()Check if emptyO(1)
size()Return countO(1)
  1. Which operation returns the top element WITHOUT removing it?
    Apush
    Bpop
    Cpeek
    Dsize
  2. The time complexity of push and pop on a stack is:
    AO(1)
    BO(log n)
    CO(n)
    DO(n^2)
  3. Discuss any five real-world applications of stacks.
Show answersHide answers
1. Option 3 — peek
2. Option 1 — O(1)
3. All standard stack operations push pop peek isEmpty size run in O(1) constant time when the stack is implemented using an array (e.g., Python list with append/pop). Stacks are widely used in expression evaluation function call management (call stack) undo features in editors browser back button and parsing algorithms.
Q31 3 Marks

Study the stack push and pop visualisation and answer:

Stacks figure
  1. A stack uses which principle?
    AFIFO
    BLIFO
    CRandom
    DPriority
  2. Which operation removes the top element?
    Apush
    Bpop
    Cpeek
    Denqueue
  3. Discuss the LIFO principle with stack push pop and peek operations.
Show answersHide answers
1. Option 2 — LIFO
2. Option 2 — pop
3. Stack follows LIFO (Last In First Out). push adds to the top; pop removes from the top; peek/top inspects without removing. All operations are O(1). Common applications include function call stack expression evaluation undo features and bracket matching.

Make a full Computer Science paper on Stacks.

Pick the question mix, set the marks, hit generate. You get a ready-to-print paper with an answer key.

Generate your paper — free