Stack

A stack is a linear data structure that follows the Last In First Out (LIFO) principle. Elements are added and removed from the same end, called the top. Common operations include push (add an element), pop (remove the top element), and peek (view the top element without removing it). Stacks are used in various applications like function call management, expression evaluation, and backtracking.

  • Time complexity for access and search is Linear, i.e. O(n)
  • Time complexity for insertion and deletion is Constant, i.e. O(1)
  • Space complexity is Linear