graphs Flashcards
Three different Types of Graphps
1) Edge Lists
2) Adjacency Matrixes
3) Adjacency Lists
Two most common ways to use graph data structures
1) Breadth First Search
2) Depth First Search
Edge List B-O
O(n)
Data structure for Edge List
Array
[0,1]
[1,2]
Adjacency Matrices B-O
O(1)
Data structure Adjacency Matrix
connect 4 type matrix (maybe battleship)
Problem with Adjacency Matrix
Takes up a lot of space
Problem with Edge List
slower
Data structure Adjacency Lists
Write each of it’s neighbors as a list in an array
0 -> [1,4] // 0 is connected to 1 and 4
1 -> [2] // only one neighbor
(an array of arrays)
Adjacency Lists 3 Advantages
1) Fast lookup
2) easy to find neighbors
3) Not as large as Adjacency Matrices
Edge List (unidirectional)
Two array lists
[0,2] [2,0]
Adjacency Matrix (unidirectional)
Flipped gride (both sides)
Adjacency Lists (unidirectional)
Just add an other item to array
0 -> [1,4,5] // 0 is connected to 1 and 4
1 -> [2,1] // only one neighbor
Breadth First Search (what is it)
start in the middle and move outward
Breadth First Search what 3 things is it used for?
1) Social Graphs
2) Recommendations
3) Nearest Neighbors