Stack is an abstract data structure similar to Queue, but follows a Last In, First Out principle.
It’s operations are inserting on top of the stack (push) and removing the most recently added element from the top of the stack (pop)
Stacks are important for supporting nested and recursive function calls and depth-first-search.

Time Complexity

OperationBig-O
Top/PeekO(1)
PushO(1)
PopO(1)
isEmptyO(1)
SearchO(n)

Corner Cases

  • Empty stack
  • Stack with one item
  • Stack with two items