More graph Algos Flashcards
Forest
is an undirected, disconnected, acyclic graph. In other words, a disjoint collection of trees
Kruskal’s algo for a connected (+ edge weighted + undirected) graph does what?
Finds a minimum spanning tree
Is kruskals greedy or Non greedy
Greedy
What is a spanning tree?
(Pertains to undirected graphs). a subgraph that is a tree which includes all of the vertices of The graph
Prim’s algo benefits vs other MST algos
for graphs that are sufficiently dense, Prim’s algorithm can be made to run in linear time, meeting or improving the time bounds for other algorithms.
List the three basic greedy algorithms to find an MST
Prim’s (Jarnik’s), Kruskal’s, Borůvka’s (Sollin’s) algorithms
Kruskals
create a forest F (a set of trees), where each vertex in the graph is a separate tree
create a set S containing all the edges in the graph
while S is nonempty and F is not yet spanning
remove an edge with minimum weight from S
if the removed edge connects two different trees then add it to the forest F, combining two trees into a single tree
At the termination of the algorithm, the forest forms a minimum spanning forest of the graph. If the graph is connected, the forest has a single component and forms a minimum spanning tree.
Topological sort definition
a linear ordering of a graph’s vertices such that for every directed edge uv from vertex u to vertex v, u comes before v in the ordering.
Canonical use case of topological sort
in scheduling a sequence of jobs or tasks based on their dependencies. The jobs are represented by vertices, and there is an edge from x to y if job x must be completed before job y can be started (for example, when washing clothes, the washing machine must finish before we put the clothes in the dryer)
List names of Topological sort implementations - Kahn, Tarjan’s DFS solution, PRAM with adjacency matrix squaring, parallelized Khan with a distributed memory machine
Kahn, Tarjan (DFS), adjacency matrix squaring on a PRAM, parallelized Kahn on a distributed memory machine
High level how to quickly compute shortest path thru weighted directed a cyclic graph
Use topological sort
Low level implementation of finding shortest paths on directed acyclic weighted graph
…
When are topological ordering a impossible
When there are cycles
DAG
Directed acyclic graph
Known Time complexity of finding a topological sorting of a DAG
O(n)
FAS stands for
Feedback Arc Set
Feedback Arc set is aka
Feedback Edge Set
Feedback arc set
set of edges which, when removed from the graph, leaves an acyclic graph. Put another way, it is a set containing at least one edge of every cycle in the graph.
What algorithm do you use to find shortest path from a source to all vertices?
Djikstra’s
Algo name for shortest path from every vertex to every other vertex
Floyd Marshall
Memory complexity of sum of length of all adjacency lists for directed graph vs undirected graph
|E| vs 2|E|
For both directed and undirected graphs the memory complexity of the adjacency list representation is
O(V + E)
disadvantage of adjacency-list representation for edges
there is no quicker way to determine if a given edge (u, v) is present in the graph than to search for v in the adjacency list Adj[u]. which worst case could be O(V) if u is connected to all vertices
List and compare two alternatives to adjacency lists to represent edges
1) have Adj[u] be a hash table containing the vertices v for which (u, v) ∈ E. Expected time is O(1). Worst case time is O(V) (if you get a lot of hash collisions (but is that really even likely???)). 2) have Adj[u] be an array that you sort and then during look-up you perform binary search for an expected and worst case time of O(lg V)`