Skip to main content
Chapter 3 of 13
NCERT Solutions

Stack — NCERT Solutions

CBSE · Class 12 · Computer Science

NCERT Solutions for Stack, CBSE Class 12 Computer Science: 11 textbook questions solved step by step. Covers Exercise.

105 questions68 flashcards5 formulas & key relations5 concepts

Interactive on Super Tutor

Studying Stack? Get the full interactive chapter.

Quizzes, flashcards, AI doubt-solver and a step-by-step study plan — built for NCERT solutions and more.

Free trial, no card needed.

An infographic illustrating various data structures like String, List, Set, Tuple, Array, Linked List, Binary Trees, Heaps, Graph, Sparse Matrix, and highlighting linear vs. non-linear structures.
Super Tutor

Learn better with visuals Super Tutor pairs illustrations like this with notes and quizzes for Stack.

Get started
11 Questions Solved · 1 Section

The first 6 solutions are open to read. The other 5 are free with a Super Tutor account. Unlock all 11 free in Super Tutor

Exercise

1aStack is a linear data structure
  1. State TRUE or FALSE for the following cases:
Show solution

A stack is a linear data structure because its elements are arranged in a sequence.

Not sure why a step works? check your working in Super Tutor

1bStack does not follow LIFO rule
  1. State TRUE or FALSE for the following cases:
Show solution

A stack follows the LIFO rule, so the statement is incorrect.

Not sure why a step works? check your working in Super Tutor

1cPUSH operation may result into underflow condition
  1. State TRUE or FALSE for the following cases:
Show solution

Underflow happens when we try to POP from an empty stack. PUSH can cause overflow, not underflow.

Not sure why a step works? check your working in Super Tutor

1dIn POSTFIX notation for expression, operators are placed after operands
  1. State TRUE or FALSE for the following cases:
Show solution

In postfix notation, the operator is written after the operands.

Not sure why a step works? check your working in Super Tutor

2aFind the output of the following code:

result=0
numberList=[10,20,30]
numberList.append(40)
result=result+numberList.pop()
result=result+numberList.pop()
print("Result=",result)

Show solution

Start with result = 0 and numberList = [10, 20, 30].

  • After append(40): numberList = [10, 20, 30, 40]
  • numberList.pop() removes 40, so result = 0 + 40 = 40
  • Next numberList.pop() removes 30, so result = 40 + 30 = 70

So the output is Result= 70.

Not sure why a step works? check your working in Super Tutor

2bFind the output of the following code:

answer=[]; output=""
answer.append('T')
answer.append('A')
answer.append('M')
ch=answer.pop()
output=output+ch
ch=answer.pop()
output=output+ch
ch=answer.pop()
output=output+ch
print("Result=",output)

Show solution

The list acts like a stack.

  • After appending: answer = ['T', 'A', 'M']
  • First pop() gives M → output = "M"
  • Second pop() gives A → output = "MA"
  • Third pop() gives T → output = "MAT"

So the output is Result= MAT.

Not sure why a step works? check your working in Super Tutor

3Write a program to reverse a string using stack.

Free with a Super Tutor account

4For the following arithmetic expression:

((2+3)*(4/2))+2
Show step-by-step process for matching parentheses using stack data structure.

Free with a Super Tutor account

5Evaluate following postfix expressions while showing status of stack after each operation given A=3, B=5, C=1, D=4

a) A B + C *
b) A B * C / D *

Free with a Super Tutor account

6Convert the following infix notations to postfix notations, showing stack and string contents at each step.

a) A + B - C * D
b) A * (( C + D)/E)

Free with a Super Tutor account

7Write a program to create a Stack for storing only odd numbers out of all the numbers entered by the user. Display the content of the Stack along with the largest odd number in the Stack. (Hint. Keep popping out the elements from stack and maintain the largest element retrieved so far in a variable. Repeat till Stack is empty)

Free with a Super Tutor account

5 more solved questions in Stack

They are free with a Super Tutor account, along with practice quizzes and flashcards for this chapter. Free to start, no card needed.

Frequently Asked Questions

What are the important topics in Stack for CBSE Class 12 Computer Science?
Key topics in Stack include Core Idea of Stack, Operations on Stack, Stack Implementation in Python, Notations for Arithmetic Expressions. Study these first, then practise questions on each for the CBSE Class 12 board exam.
Are these NCERT Solutions for Stack free?
The first 6 of the 11 solutions on this page are open to read. The other 5 are free with a Super Tutor account — signing up is free and needs no card.
How should I revise Stack for the CBSE Class 12 board exam?
Learn the core ideas first, then work through the 105 practice questions on Stack. Revise definitions regularly and use flashcards for quick recall before the exam.

Sources & Official References

Content is aligned to the official syllabus. Refer to the board website for the latest curriculum.

For serious students

Get the full Stack chapter — start free.

Quizzes, flashcards, an AI doubt solver and a study plan for CBSE Class 12 Computer Science. Free to start, no card needed.