push and pop
The two basic stack operations: push adds an item to the top and pop removes and returns the item on top.
In more detail
In Python, list.append is push and list.pop() with no argument is pop, both O(1). list.pop(0) removes from the front instead, which costs O(n). Heaps also speak of push and pop, meaning insert and remove-smallest.
Related terms
- stack — A collection where the last item added is the first one removed, like a pile of plates.
- Python list — Python's built-in ordered, growable sequence, implemented as a dynamic array of pointers to objects.
- heapq — Python's standard-library module of functions that treat an ordinary list as a binary min-heap.
Taught in
- Recognising The Common Growth Rates — Algorithms & Data Structures for Working Engineers
- Stacks And Queues: Last In Or First In — Algorithms & Data Structures for Working Engineers
- Deques And Ring Buffers — Algorithms & Data Structures for Working Engineers
- Choosing The Right Sequence — Algorithms & Data Structures for Working Engineers
- Heaps And Priority Queues — Algorithms & Data Structures for Working Engineers
- Dijkstra: Shortest Paths With A Priority Queue — Algorithms & Data Structures for Working Engineers