39 lines
924 B
Markdown
39 lines
924 B
Markdown
# 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
|