0% found this document useful (0 votes)
6 views2 pages

Stack and Expression Conversion Notes

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views2 pages

Stack and Expression Conversion Notes

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Stack and Expression Conversion – Class 12

Computer Science (Exam Notes)

Section A – 2 Mark Questions


Q: Define data structure. Give an example.
A data structure is a way of organizing and storing data efficiently. Example: Stack,
Queue, List.

Q: Differentiate between list and string.


List is mutable and can hold multiple data types, while String is immutable and holds
only characters.

Q: What is a stack? What is its ordering principle?


A stack is a linear data structure that follows the LIFO (Last In First Out) principle.

Q: Define stack. Give one real-life application.


A stack allows insertion and deletion only from one end (top). Example: Undo/Redo in
text editors.

Q: Name fundamental stack operations.


Push (insert), Pop (delete), Peek (view top), isEmpty, isFull.

Q: What is overflow and underflow in stack?


Overflow occurs when pushing into a full stack; underflow occurs when popping from
an empty stack.

Q: What is prefix and postfix expression?


Prefix: Operator before operands (e.g., +AB). Postfix: Operator after operands (e.g.,
AB+).

Q: Python code for push operation.


stack = [] [Link](10) print(stack)

Q: Python code for pop operation.


stack = [10, 20, 30] [Link]() print(stack)

Q: Define prefix, infix, and postfix with examples.


Infix: A+B, Prefix: +AB, Postfix: AB+.

Section B – 3 Mark Questions


Q: Define stack and give two real-life applications.
Stack is a LIFO structure where insertion and deletion happen at the top. Applications:
Undo/Redo, Browser history.
Q: Explain operations performed on stack.
Push – insert element, Pop – remove top element, Peek – view top element without
removing it.

Q: Python implementation to create and count stack elements.


stack = [] [Link](10) [Link](20) print('Stack:', stack) print('Count:',
len(stack))

Q: List applications of stack in programming.


Used in recursion, expression evaluation, syntax parsing, and function call
management.

Q: What are types of arithmetic expressions?


Infix: Operator between operands, Prefix: Operator before operands, Postfix: Operator
after operands.

Section C – 5 Mark Questions


Q: What is a stack? Explain applications in real life.
Stack follows LIFO principle. Applications include: 1. Undo/Redo in editors 2. Browser
navigation 3. Expression evaluation 4. Function calls 5. Reversing data.

Q: Explain stack operations with Python code.


stack = [] def push(item): [Link](item) def pop(): if not stack: print('Underflow!')
else: [Link]() def display(): print('Stack:', stack) push(10) push(20) display() pop()
display()

Q: Explain types of arithmetic expressions with examples.


Infix: A+B (operator between) Prefix: +AB (operator before) Postfix: AB+ (operator
after).

Q: Algorithm to convert infix to postfix.


1. Initialize empty stack and result. 2. Scan infix from left to right. 3. If operand → add
to result. 4. If '(' → push to stack. 5. If ')' → pop until '(' appears. 6. If operator → pop
higher precedence operators, then push current. 7. Pop remaining operators to result.

Q: Algorithm to evaluate postfix expression.


1. Initialize empty stack. 2. Scan postfix left to right. 3. If operand → push to stack. 4. If
operator → pop two operands, perform operation, push result. 5. Final stack element
is result.

Q: Convert (A+B*C-D) to postfix.


Stepwise conversion → ABC*+D- Result: ABC*+D-.

Q: Evaluate postfix expression 543-*.


Push 5,4,3 → Stack=[5,4,3] '*' → 4*3=12 → Stack=[5,12] '-' → 5-12=-7 → Result=-7.

You might also like