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
What does a spanning subgraph have?
Same nodes but a subset of edges
What is a forest?
graph without cycles
What is traversal?
A systematic procedure for visiting all edges and nodes in a graph
Which is recursive, DFS or BFS?
DFS
What do nodes of a level in BFS have in common?
same distance from a fixed node
Both BFS and DFS have the same complexity which is?
O(n+e)
How are live objects signified in the mark and sweep algorithm?
mark
How is the digraph connected to the mark and sweep algorithm?
Each object in memory heap is a vertex
Each reference is an edge
What does the mark phase of mark and sweep involve?
1.Directed DFS on root objects to identify live objects