data structures Flashcards
stack
data can be added or removed from one location - the TOP of the stack
LIFO (last in first out) structure
stack operations
push() - add an item to the top of the stack
pop() - take an item from the top\
limitations on stack operations
cant push if stack full
cant pop if stack empty
how push() stack operation is carried out
push - add an item at the top pointer and then move the top pointer up by one
how pop() stack operation is carried out
pop - return the value at the top pointer then move the top pointer down by one
evaluate the stack
traverse or insert is not possible
big-O value of all stack operations is one
no wasted space
when stack is used
- undo button
- recursive function
queue
data can be added at the end/ tail of the queue
can be removed at the front/ head of the queue
FIFO ( first in first out) structure
queue operations
Enqueue - add item to end of queue
Dequeue - take an item from front of queue
how enqueue() queue operation is carried out
add an item at the end marker
move it forward by one
how dequeue() queue operation is carried out
return value at front marker and move it forward by one
limitations of queue operations
- queue moves along in available space as changes are made
- to avoid running out of space it can be made circular. if the end of the queue catches up w the front, no more items can be added
evaluate queue
traverse insert not possible
big- O value of all queue operations is 1
no wasted space
when queue is used
print queue
linked list
made of nodes
each node contains an item of data and a pointer to the next node