This commit is contained in:
Medium Fries
2019-03-15 01:26:26 -07:00
parent fa12687849
commit ea2aa8d2a6
17 changed files with 415 additions and 0 deletions

6
370/notes/1.md Normal file
View File

@@ -0,0 +1,6 @@
# lec1
> trees & tree heaps
> also: ilearn still busted but theres a survey to fill out
bin search trees
max/min/heap trees

13
370/notes/2.md Normal file
View File

@@ -0,0 +1,13 @@
# Divide and Conquer
Make big problem into smaller problems to solve
## Merge Sort
_yote_
1. find midpoint of list
2. split into two smaller lists
3. keep splitting smaller lists until we have a bunch of 1/2 size lists
4. sort each using the _smaller_ already sorted values against each other into a new sub-list
5. combine and sort each thing

38
370/notes/adj-list.md Normal file
View File

@@ -0,0 +1,38 @@
# Adjacency list
Imagine 8 nodes with no connections
To store this data in an _adjacency list_ we need __n__ items to store them.
We'll have 0 __e__dges however so in total our space is (n+e) == (n)
# Adjacency matrix
space: O(n^2)
The convention for notation btw is [x,y] meaning:
* _from x to y_
# Breadth first search
add neighbors of current to queue
go through current's neighbors and add their neighbors to queue
add neighbor's neighbors
keep going until there are no more neighbors to add
go through queue and start popping members out of the queue
# Depth first search
Here we're going deeper into the neighbors
_once we have a starting point_
_available just means that node has a non-visited neighbor_
if available go to a neighbor
if no neighbors available visit
goto 1
# Kahn Sort
# Graph Coloring
When figuring out how many colors we need for the graph, we should note the degree of the graph

32
370/notes/avl-trees.md Normal file
View File

@@ -0,0 +1,32 @@
# Self balancing trees aka AVL trees
_time complexity will be in terms of height_
> Height:
distance from nulls after leaves
* impl: _root will typically have the largest height value_
> Balance:
| left_height - right_height |
we can discard the || if we want negative balance vals but it really shouldn't matter
basically: we want the balance for each node to be 1 or 0.
# Self balancing part
We maintain balance through the tree's lifetime as we insert/delete things into the tree
> Insertion/Deletion
* just like BST but we balance starting from the new node
# Restoring balance
There are 4 special cases when dealing with restoring balance:
1. left-left
2. left-right
3. right-left
4. right-right
# Tries

60
370/notes/big-o.md Normal file
View File

@@ -0,0 +1,60 @@
# Calculating Big O
Suppose we have the following function
```
func(x):
if cond1
O(n^2)
elif cond2
O(n)
else
O(1)
```
How do we define the _average_ time complexity:
* any input which isn't setup to be _special_
1. linear search which always finds the first elementO(1)
2. linear search that doen't find anything/last elementO(n)
With linear searches: finding an average item in the middle(somwhere) we have to cover:
* x% of the n size list
Since we drop the constants in time complexity expressions we thus end up with O(n).
## Heap Sort
Time Complexity Exercise
* Best:
* Average:
* Worst:
* Space:
## Insertion Sort
Time Complexity Exercise
* Best:
* Already sorted meaning we go through the whole list once
* O(n) - because we'll do the check into our left sub-list but we don't go into it leaving us as constant time spent per item ie c\*n
* Average:
* Pretty close to n^2 just for the sake of
* O(n^2)
* Worst:
* Going through the whole list sorting everything(backwards)
* O(n^2)
* must go through N items for each item
* Space:
# Notation
Time Complexity: O(n)
Space Complexity: OMEGA(n)
Both Complexity: THETA(n)
* such a complexity only exists if O(n) == OMEGA(n)

27
370/notes/complex.md Normal file
View File

@@ -0,0 +1,27 @@
# Complexities
yote we talkin about space and time complexity
* Space
How much space this shit takin up
* Time
How fast something it's gonna take
* Both time/space complexity notation
_O(?)_: this notation is used for both space and time complexity
# Scale of Complexity
O(n) we refer as a linear because the higheset order exponent is /1/
The higher the max order of the expression the higher order the overall complexity(duh).
Non-polynomial expressions are just non-polynomial expressions(yote).
In other words the part most people care about is the highest order exponential value in the function/expression, since everything else _will_ be faster than that.
If you want to jam jargon in there go ahead but don't overthink this tbh famalamasham.

3
370/notes/graphs.md Normal file
View File

@@ -0,0 +1,3 @@
# Graph
_First of a few pages on graphs_

20
370/notes/sorts.md Normal file
View File

@@ -0,0 +1,20 @@
# Cheatsheet for sorts
_using pythonic terminology for these cases_
> Bubble
* take the largest value and buble it to the top/front of the list
> Insertion
> Selection
* take smallest value and drop it to the front
> Merge
* split the hell out of things and sort from the inside out
* goes from side to side
> Heap
* grab max item and append it to a heap
> Quick

16
370/notes/space.md Normal file
View File

@@ -0,0 +1,16 @@
# Space complexity
With function calls there is explicit space used.
Implicit space used is about how much work is done to take up space
# Binary recursive search
> Explicit space: O(c)
This is the amount of space taken per call.
We know how much space has to be allocated every call so we can say it would likely be constant
> Implicit: O(log(n))
Because again we will likely take up log(n) times to reach our destination an this comes from our rekked stackspace.

20
370/notes/tries.md Normal file
View File

@@ -0,0 +1,20 @@
# Tries - Prefix Trees(syntax trees in disguise)
We can build grammers from symbols where symbols follow a set of rules to build on each other.
Kinda like linguistic sytax trees but, exactly the same.
_Individual syntaxes are combined to build grammers combine to build phrases, etc. etc._
Instead of symbols we use _prefixes_ as our terminology, to build _words_.
Terminally sequenced symbols are denoted by a _leaf_ flag.
# Deletion
We don't actually remove things for trivial cases.
Instead we turn off the leaf flag in the end target node
if we have /bathe/ and /bathes/ as valid phrases and wanted to remaove /bathe/ from our language
* All we have to do is set the /e/ to off as a valid leaf.
If instead we wanted to remove /bathes/ instead we would go to /s/ and then set it to off like before.
* The problem now is that /s/ is hanging and it doesn't have any children so we can remove it entirely
* If a toggled off node has children it means that it necessarily is part of a valid prefix so it can not be removed