Abstract Data Types
In computer science, an abstract data type (ADT) is a mathematical model for data types.
An abstract data type is defined by its behavior (semantics) from the point of view of a user, of the data, specifically in terms of possible values, possible operations on data of this type, and the behavior of these operations.
Stack
A stack is a Last-In First-Out (LIFO) abstract data structure
Attributes: A container that holds multiple data
Methods:
Push
→ Adds Element to the top of the stackPop
→ Removes the most recently added ElementPeek
→ Look at the most recent element
Optional Methods:
size()
-> Returns the number of items in the StackisEmpty()
-> Returns True if the stack is empty
Stack & Complexity
All of stack operations are O(1)
with Space complexity being O(n)
.
Stack Implementation in Python
Last updated