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

Stack Data Structure Overview and Usage

The document provides concise notes on Chapter 3: Stack, detailing the definition, operations, and applications of stack data structures, which follow the Last In First Out (LIFO) principle. It includes methods for implementing stacks in Python, as well as notations for arithmetic expressions and the process of converting infix to postfix expressions. Additionally, it explains how to evaluate postfix expressions using stacks.

Uploaded by

davanshtyagi166
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)
3 views2 pages

Stack Data Structure Overview and Usage

The document provides concise notes on Chapter 3: Stack, detailing the definition, operations, and applications of stack data structures, which follow the Last In First Out (LIFO) principle. It includes methods for implementing stacks in Python, as well as notations for arithmetic expressions and the process of converting infix to postfix expressions. Additionally, it explains how to evaluate postfix expressions using stacks.

Uploaded by

davanshtyagi166
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

do same again with this one

Here are easy and understandable notes in pointer form for Chapter 3: Stack from your PDF:
Introduction to Data Structures
Data structures organize and store data for efficient access and processing.
Examples: String, List, Set, Tuple.
Stack is a linear data structure following Last In First Out (LIFO) principle.
What is Stack?
Elements added and removed only from one end called the "top".
Last element added is the first to be removed (LIFO).
Examples: Stack of plates, pile of books.
Applications of Stack
Undo/redo functionality in text editors.
Browser back button to visit previously browsed pages.
Checking matching parentheses in expressions.
Memory management in operating systems.
Operations on Stack
PUSH: Add element to top of the stack.
POP: Remove element from top of the stack.
Stack overflow occurs if trying to push an element when stack is full.
Stack underflow occurs if trying to pop from an empty stack.
Implementing Stack in Python
Use list type to implement stack.
Use list's append() to push elements.
Use list's pop() to remove elements.
Functions:
isEmpty(stack): Check if stack is empty.
opPush(stack, element): Push element.
opPop(stack): Pop element.
top(stack): Get top element.
size(stack): Number of elements.
display(stack): Show all stack elements.
Notations for Arithmetic Expressions
Infix: Operators between operands (human-readable).
Prefix (Polish): Operators before operands.
Postfix (Reverse Polish): Operators after operands.
Postfix is easy to evaluate by computers using stacks.
Infix to Postfix Conversion
Use stack to store operators.
Traverse infix expression left to right, output operands to postfix string.
Push operators on stack according to precedence.
Pop from stack when needed based on precedence and parentheses.
Result is postfix expression without parentheses.
Evaluating Postfix Expression
Traverse postfix expression.
Push operands on stack.
When operator encountered, pop two operands, apply operator, push result.
Final value in stack is the evaluated result.
These notes cover key concepts and operations about stack data structure and arithmetic
expression handling for your notebook writing and revision. Let me know if you want more
details or examples.

1. [Link]

You might also like