CBSE · Class 12 · Computer Science
Class 12 Stack Mock Test (CBSE)
5 practice questions from Stack, in the style of your board paper, each with a worked answer and the marks for every step. Then take a full chapter test on paper, snap the pages and get every step marked.
Topics in Stack
- Introduction to stack
- Operations on stack: push and pop
- Implementation of stack in Python
- Notations for arithmetic expressions
- Conversion from infix to postfix notation
- Evaluation of postfix expression
Stack practice questions with answers
- Q1Multiple choice1 markIn a cafeteria, clean plates are placed one above another on a spring-loaded stack, and a customer always takes the plate that was placed last. Which principle does a stack follow, and why does it explain this behaviour?
- (a)First In, First Out (FIFO), because the earliest plate is removed first
- (b)Last In, First Out (LIFO), because the most recently added item is removed first
- (c)Random access, because any plate can be taken from any position
- (d)Priority order, because the heaviest plate is always removed first
Show answer and step marks
- Correct option: (b) Last In, First Out (LIFO), because the most recently added item is removed first+1
Answer: (b) - Q2Multiple choice1 markAt a museum cloakroom, visitors' bags are kept one above another in a pile, and each visitor collects the bag currently on top of the pile. If this pile is stored as a Python list used as a stack, which statement correctly describes how the top bag is collected?
- (a)Use pop() on the list, which removes the last element added
- (b)Use pop(0) on the list, which removes the first element added
- (c)Use push() on the list, which removes the top element
- (d)Use append() on the list, which removes the top element
Show answer and step marks
- Correct option: (a) Use pop() on the list, which removes the last element added+1
Answer: (a) - Q3Short answer2 marksA stack of integers is implemented in Python using a list named S. The following statements are executed in the given order: S = [] S.append(12) S.append(7) S.append(25) S.pop() S.append(9) S.pop() S.pop() (a) Write the content of the list S after all the statements are executed. [1] (b) State the value returned by the last pop() statement. [1]
Show answer and step marks
- Correct content after the statements: S = [12], because 12, 7, 25 are pushed, 25 is popped, 9 is pushed and popped, and 7 is popped last.+1
- The last pop() removes the top element 7, so the value returned is 7.+1
Answer: (a) S = [12]; (b) 7 - Q4Short answer3 marksX: A × B + C and Y: A × (B + C) are two infix expressions. (a) Convert X into postfix notation. [1] (b) Convert Y into postfix notation. [1] (c) Explain why the postfix forms of X and Y have their operators in a different order, even though both use the same operands in the same order. Give a reason. [1]
Show answer and step marks
- (a) In X, * has higher precedence than +, so A B × is formed first and then + is placed last, giving A B × C +.+1
- (b) In Y, the brackets make B + C the first operation, so the operands are A B C + and then × is placed last, giving A B C + *.+1
- (c) The brackets in Y change the order of operations, so + is written before × in the postfix form; in X, * is written before +, because × has higher precedence than +.+1
Answer: (a) A B × C + (b) A B C + * (c) Brackets in Y force B + C to be evaluated first, so the postfix order of operators changes; in X the usual precedence makes × come before +. - Q5Short answer3 marksEach of the following expressions represents the same value. P: 6 2 + 4 × Q: * + 6 2 4 R: (6 + 2) × 4 (a) Name the notation used by P. [1] (b) Name the notation used by Q. [1] (c) Explain why R needs brackets while P and Q do not. Give a reason. [1]
Show answer and step marks
- (a) P is in postfix notation, since each operator is written after its two operands.+1
- (b) Q is in prefix notation, since the operator × is written before its operands.+1
- (c) R is infix, so the position of × does not fix the order of evaluation; brackets are needed to override precedence. In P and Q, the position of each operator alone fixes the order, so no brackets are needed.+1
Answer: (a) Postfix notation. (b) Prefix notation. (c) In infix notation the operator position does not fix the order of evaluation, so brackets are needed. In postfix and prefix notation the operator position fixes the order, so brackets are not needed.
Take a full Stack test
PrepitUp writes a fresh paper on this chapter at the length you pick. Write it on paper with a timer, photograph the pages, and see the marks for every step and what to practise next.
- 15 min10 marks
- 30 min20 marks
- 1.5 hr40 marks
- 3 hr80 marks
Get your Stack answers marked
Sign in, pick this chapter and a length, write the test on paper and get every step marked.
Sign in to take this test