The tools you use to accomplish your task Algorithms are the recipe: The set of instructions you follow. Will specify what data structure to use
There are niche data structures that most developers could never use Once you get into specialized applications, they can be handy
Arrays => lists Objects => dictionaries
Objects and lists can get you very far Not optimized for any one task
A list is a contiguous block in memory where you store your list of things Predefined amount of space Can add/remove because they’ve added that functionality Canonically with an array/list, it is a static amount of size In JS and Python, if you start off with a list, it’s extra work to add to it because you have to expand the space in the list to accommodate additional data
For the purposes of what we’re talking about today, assume a list/array is only a predefined amount of space
Linked List represents a list in a different way:
With an array/list, you have a predefined amount of space and if you want to add to it later on, more work to expand the amount of space available to the list/array
Linked List inverts that - is constructed in terms of the individual elements
1->2->B->4->5->null
1 knows about 2 knows about B knows about 4 knows about 5 knows about nullIf you have an array/list and say it’s 10 spots, it will take up 10 spots in memory even when empty Empty linked list takes up no memory
Node is a dictionary/object/class that holds a value and a next
Linked List class - head and tail
1->2->3->N
Head - first node in the list
Tail - last node in the list
Can recreate using a list or array
Encapsulates the functionality you get when you end up in a line
When you join, you’re at the back
When you leave, you’re at the front
Stay for duration of the line
First in first out
Enqueue - add to the end
Dequeue - remove from front
lens - length of the list
Catch - will use linked list that you made in order to implement the queue
self.storage = LinkedList()
Adding and removing from linked list
5->N
H->T
Remove H
Last in first out
Tree is like a linked list
With node you can have multiple pointers
Binary is enforcing that there is only max two children from any one node
Left < parent <= right
If adding input, need to put into node and compare to root of tree
If already has a node on the side the new node would fit, keep traversing that side of the tree until there is space for it
contains - if a value exists in the binary search tree get_max - maximum value of the binary search tree
How do we design a data structure to get max value ASAP We’ll be implementing max heap
Fastest way to access something in an array - index Heap tries to take advantage of that Top of the heap is always the max (in max heap) Not binary search tree because not the same rules Multiple ways to represent heap Makes more sense to implement it as a binary tree, but sometimes makes more sense to implement as array
insert 101
Like binary search trees, there are rules for how heaps are laid out Direct children have to be less than parents
[0, 100, 19, 36, 17, 12, 25, 5, 9, 15, 6, 11, 13, 8, 1, 4]
node = i
left = 2i
right = 2i + 1
child to parent = floor(i/2)
No nodes in heap, just an array with values Tree was because intuitive to talk about heaps in that case Array integer
Draw everything out with different inputs to see how things will work