The document discusses stacks, which are linear data structures that follow LIFO order. The core stack operations are push, pop, peek, and isEmpty, which all have O(1) time complexity. Stacks have many applications, including balancing symbols, converting infix to postfix notation, undo/redo features, and algorithms like tower of Hanoi and tree traversals. Stacks can be implemented using arrays or linked lists.
2. STACK
Stack is a linear data structure which follows a particular order in which the operations
are performed. The order may be LIFO(Last In First Out) or FILO(First In Last Out).
Mainly the following three basic operations are performed in the stack:
Push: Adds an item in the stack. If the stack is full, then it is said to be an Overflow
condition.
Pop: Removes an item from the stack. The items are popped in the reversed order in
which they are pushed. If the stack is empty, then it is said to be an Underflow
condition.
Peek or Top: Returns top element of stack.
isEmpty: Returns true if stack is empty, else false.
4. STACK
Time Complexities of operations on stack:
push(), pop(), isEmpty() and peek() all take O(1) time. We do not run any loop in any of
these operations.
5. APPLICATIONS OF STACK:
Balancing of symbols.
Infix to Postfix /Prefix conversion .
Redo-undo features at many places like editors, photoshop.
Forward and backward feature in web browsers.
Used in many algorithms like Tower of Hanoi, tree traversals, stock span
problem, histogram problem.
Other applications can be Backtracking, Knight tour problem, rat in a maze, N queen
problem and sudoku solver.
In Graph Algorithms like Topological Sorting and Strongly Connected Components.