Core9X
Log inSign up

MBOSE Class XII Computer Science · Chapter 3

Stack

Opening soon

How a stack works on the last-in, first-out rule, how to build one in Python, and how it helps evaluate expressions.

17 lessons · 56 practice questions · unit "Computational Thinking and Programming" carries 40 marks

See classes open nowLog inMBOSE Class XII opens to new students soon.

What this chapter covers

  • Data structures
  • Stack and the LIFO principle
  • Applications
  • Operations — PUSH, POP, overflow, underflow, isEmpty, top, size, display
  • Implementation in Python using a list
  • Infix, prefix and postfix notations
  • Conversion of infix to postfix
  • Evaluation of postfix expressions

Key terms

Data structure

Way of organising data in memory for efficient use

Stack

Linear structure with insertion and deletion at one end

LIFO

Last In, First Out

TOP

End of the stack where operations happen

PUSH

Adding an element at the top

POP

Removing the top element

Overflow

Pushing onto a full stack

Underflow

Popping from an empty stack

Infix

Operator between operands

Postfix

Operator after operands

Prefix

Operator before operands

Important questions with answers

10 of the 56 questions on this chapter, solved.

  1. Question 1 · Multiple choice · 1 mark

    A stack follows the principle of

    • (a) LIFO
    • (b) FIFO
    • (c) random order
    • (d) sorted order

    Answer: (a) LIFO

    Last In, First Out.

  2. Question 2 · Multiple choice · 1 mark

    The peek (top) operation

    • (a) removes the top element
    • (b) adds an element
    • (c) empties the stack
    • (d) returns the top element without removing it

    Answer: (d) returns the top element without removing it

    stk[-1] in Python.

  3. Question 3 · Multiple choice · 1 mark

    When (A+B)*C is converted to postfix, the result is

    • (a) AB+C*
    • (b) ABC+*
    • (c) +AB*C
    • (d) AB*C+

    Answer: (a) AB+C*

    The bracket is evaluated first.

  4. Question 4 · Multiple choice · 1 mark

    While evaluating postfix, on reading an operator we

    • (a) pop two operands, apply the operator and push the result
    • (b) push the operator
    • (c) pop one operand
    • (d) print the operator

    Answer: (a) pop two operands, apply the operator and push the result

    The first popped is the right operand.

  5. Question 5 · Assertion and reason · 1 mark

    Assertion (A): The element pushed last is popped first.

    Reason (R): A stack follows LIFO.

    • (a) Both A and R are true, and R is the correct explanation of A.
    • (b) Both A and R are true, but R is not the correct explanation of A.
    • (c) A is true, but R is false.
    • (d) A is false, but R is true.

    Answer: (a) Both A and R are true, and R is the correct explanation of A.

    Last In, First Out.

  6. Question 6 · Short answer · 2 marks

    Define a stack.

    Answer

    A linear data structure in which insertion and deletion happen only at one end (TOP), following LIFO.

  7. Question 7 · Short answer · 2 marks

    Why is postfix preferred by computers?

    Answer

    It needs no brackets or precedence rules and is evaluated in one scan with a stack.

  8. Question 8 · Short answer · 3 marks

    Distinguish overflow and underflow.

    Answer

    Overflow is pushing onto a full stack; underflow is popping from an empty one.

  9. Question 9 · Long answer · 5 marks

    Explain the stack and its operations with a Python implementation.

    Answer

    Sections 1.2–1.4; Section 8.2 (HSSLC 2024, Q9(b) (second choice)).

  10. Question 10 · Long answer · 5 marks

    Give the algorithm to evaluate a postfix expression and evaluate 50 60 + 20 10 - *.

    Answer

    Section 1.7; Section 8.2 (HSSLC 2025, Q3(a)).

Study the whole chapter

17 step-by-step lessons, all 56 practice questions with hints, flashcards and mock tests for MBOSE Class XII Computer Science.

See classes open nowLog inMBOSE Class XII opens to new students soon.