Skip to content

Latest commit

 

History

History
70 lines (50 loc) · 3.04 KB

readme.md

File metadata and controls

70 lines (50 loc) · 3.04 KB

Stack

Theory

Stack

  • A stack is a linear data structure that follows the LIFO (Last-In-First-Out) principle.
  • The last element inserted is the first one to be deleted.

Stack Operations

  • Push: Insert an element at the top of the stack.
  • Pop: Delete an element at the top of the stack.
  • Peek: Get the value of the top element without removing it.
  • IsEmpty: Check if the stack is empty.
  • IsFull: Check if the stack is full.

Stack Applications

  • Balancing of symbols
  • Infix to Postfix/Prefix conversions
  • 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.

Stack Implementation

  • Using Array
  • Using Linked List

Stack Time Complexity

  • Push: O(1)
  • Pop: O(1)
  • Peek: O(1)
  • IsEmpty: O(1)
  • IsFull: O(1)

Stack Space Complexity

  • O(n)

Stack Example

  • Undo/Redo
  • Backtracking
  • DFS

Problems

References

Category: Stack Status: Done Author: David Bujosa