Graphs Flashcards
When is an graph connected?
- undirected
- > =1 vertex
- there’s a path between every pair of vertices
What is the complexity of Dijkstra’s shortest path algorithm when using an Adjacency list and PQ?
O((n+e)*log(n))
Dijkstra pseudo code
(min distance from v to all) while PQ not empty -remove u with min distance from PQ -for each adjacent vertex z -if D[u] +w(u,z)
What kinda graph does Bellman-Ford shortest path algorithm work on?
Directed
What makes Bellman-Ford different from Dijkstra?
negative weights allowed
Complexity of Bellman-Ford algorithm?
O(n*e)
How would you define a graph (informal)?
A set of nodes
- containing some USEFUL INFOrmation
- connected by edges
How would you define a graph (formal)?
G(E,v)
- Set of V vertices
- Collection E oF PAIRS of vertice, edges
What is the complexity of Dijkstra when using a list as a priority queue?
O(n^2)
When is a digraph strongly connected?
if v is reachable from u, u is reachable from v
What is the transitive closure of a graph G?
- G* that has the same vertices as g
- wherever there’s a path from (u,v) in G, G* has an edge
What is the algorithm to compute the transitive closure called?
Floyd-Warshall
The floyd warshall algorithm makes an initial copy of G and then traverses all nodes and their reachable pairs.
What 3 conditions needs to hold for it to add a directed edge (Vi,Vj) to Gk?
Edge (Vi,Vj) exists in Gk-1 (prev graph)
Edge (Vj,Vk) exists in Gk-1
Edge doesn’t already exist in Gk
What is the asymptotic time complexity of the Floyd Warshall algorithm?
O(n^3)
What is the degree of a vertex?
number of edges incident to it