Stacks and Queues Flashcards
What is used to make a stack?
Linked Lists
What is the runtime of push?
O(1)
Which structure if LIFO and define LIFO.
Stack is LIFO; last in first out. Whatever the last element added in to the array will be the first element removed.
What is the runtime of pop?
O(1)
What can stacks not do?
No searching or sorting. Can only use the push and pop functions.
Which structure is FIFO and define FIFO.
Queue is FIFO; first in first out. Whatever is the first element in the array is the first element to be removed.
What is the runtime of enqueue?
O(1)
Adds elements to the back
What is the runtime of dequeue?
O(1)
Removes elements from the front
What can queue not do?
No searching or sorting. Can only enqueue and dequeue (add and remove).
How do we make the functions in queue O(1)?
By keeping track of the tail (end) node.