Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

Stacks

A stack is an abstract linear data structure that serves a particular perfomance of operations. The principle operations are; push and pop LIFO - Last In First Out

The name "stack" for this type of structure comes from the analogy to a set of physical items stacked on top of each other.Stacks can be used with Arrays or Linked List

A stack is implemented using a dynamic array or a singly linked list
Arrays - allow cache locality, which make them technically fast when accessing items.
Linked List - have extra memory associated with them, because we have to hold on to the pointers
On the other hand, Linked List have more dynamic memory compared to Arrays.


Constraints

  • Empty stack. Popping from an empty
  • Stack with one itme
  • Stack with two items

Basic operations

Lookup pop push peek isEmpty
O(n) O(1) O(1) O(1) O(1)
  • push - add element to the last item
  • pop - remove the last element
  • Peek/top - view the top most item

Check below leetcode questions

  1. Valid Parentheses
  2. Implement Queue using Stacks
  3. Generate Parentheses
  4. Min Stack
  5. Asteroid Collision
  6. Evaluate Reverse Polish Notation
  7. Basic Calculator
  8. Basic Calculator II
  9. Daily Temperatures
  10. Car Fleet
  11. Trapping Rain Water
  12. Largest Rectangle in Histogram

References

  1. Coursera
  2. Medium
  3. Udemy
  4. Design Gurus