Linked List
Normally, inserting into a list is constant time and inserting into an array is $O(n)$. Behind the scenes a python list is built as an array, so insert into a python list is $O(n)$ and finding an element is $O(1)$.
1 |
|
Stack
Python has a built-in function to turn a list into a stack, but we can code it as well.
1 |
|
Queue
Python has a built-in queue function that is using a library collections
’s package deque
, which was designed to have fast appends and pops from both ends. Also, we can build our own enqueue from only one side.
1 |
|
Reference: Udacity Technical Interview Course