data structures
No description yet. This curated deck is ready for daily study.
Card preview (24)
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
how to traverse a linked list
start at header follow pointers until reach node with no pointers
how to insert items to a linked list
add the item in an empty space change pointers to include item in the list
how to delete items from a linked list
change pointers so that the list skips over the deleted item
What does the free space pointer do
computer remembers the location of an empty storage space this is where new nodes can be added after adding a new node the free space pointer is updated
evaluate linked list
• wide range of operations possible. traverse, search , insert, sort, delete etc. • most operations have O(n) - linear complexity, making the linked list slower than a stack or queue
when to use a linked list
list data type in python
tree data structure
made of nodes each node holds one data value and more than one pointer
parts of a tree data structure
root - start value branches - nodes to left and right of root leaf node- a node with no branches
binary tree
made of nodes with two pointers