graphs Flashcards

1
Q

adjacency matrix facts

A

Given two vertices u and v: find out whether u and v are adjacent –> O(1)

Given a vertex u: enumerate all neighbors of u –> O(n)

For all vertices: enumerate all neighbors of each vertex O(n^2)

memory space is O(n^2)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

adjacency list facts

A

Given two vertices u and v: find out whether u and v are adjacent –> degree of node O(n)

Given a vertex u: enumerate all neighbors of u –> degree of node O(n)

For all vertices: enumerate all neighbors of each vertex summations of all node degree O(m)

memory space is O(m)

better for sparse graphs

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

when is a graph sparse?

A

a graph is spare is the number of edges is less than the number of nodes squared

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

dijkstra’s algorithm

A

finding shortest path from node to node, traversing

time complexity: O(n log n + m log n(

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

bellman-ford

A

shortest path, the one with going through each node and seeing if there can be a new shortest path by relaxing

time complexity O(m * n)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

kruskal’s algorithm

A

minimum spanning tree found by the next shortest absolute node that doesn’t create a cycle

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

prim’s algorithm

A

minimum spanning tree found by the next shortest traversal

O(n^2) for dense graph
O(m log n) for sparse graph

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly