Exam 2 Flashcards
What does V represent?
Set of vertices
What does E represent?
Set of edges
What does n = |V| represent?
Number of vertices
What does m = |E| represent?
Number of edges
What does s represent?
The source vertex
What does t represent?
The sink vertex
What is Breadth-first Search (BFS) algorithm used for?
To find unweighted Single Source Shortest Path (SSSP), the distance from s to u if s can reach u, otherwise it is infinity; Runtime is O(n+m)
What is Dijkstra’s algorithm used for?
To find weighted Single Source Shortest Path (SSSP), the distance from s to u if s can reach u, otherwise it is infinity; Understand that when weights are involved, the runtime increases to O((n+m) log n)
What is Depth-first Search (DFS) algorithm used for?
It behaves differently for directed and undirected graphs; In a directed graph, the pre/post numbers give information on how a graph COULD be explored; In an undirected graph, the pre/post numbers give information on how a graph WOULD be explored given a starting point; Runtime is O(n+m)
What is the Explore algorithm used for?
This is a subroutine of DFS and does most of the work in DFS, it runs on all edges and vertices that are reachable from the provided v, can be used with a visited array to will set to true for all nodes u that are reachable from v; Runtime is O(n+m) if run by itself
What is the Topological Sort algorithm used for?
This algorithm works by running DFS on the DAG (directed acyclic graph - it has no cycles) and using the post order number to sort the vertices from highest post number to lowest post number, when a DAG is ordered from source to sink, then all edges go from left to right; Runtime is O(n+m)
What is the Strongly Connected Components (SCC) algorithm used for?
It takes a directed graph and runs DFS twice, running once with pre/post order numbering on the reverse graph of G and sorting V in descending post order numbers, giving sink to source; It then runs again on G with V sorted, the output will have ccnum representing each SCC with highest = source, and lowest = sink, the ccnum can be used to gather up vertices that belong to each SCC; Runtime is O(n+m)
What is Kruskal’s Minimum Spanning Tree (MST) algorithm use for?
The algorithm sorts edges by weight of a connected and undirected graph, G = (V,E), and weights w, it grabs the lightest available edge that will not create a cycle when added to the MST, another way to look at this is to never add edges of vertices in the same component in the MST, this continues until all edges that will not create a cycle are added, this happens at exactly n-1 edges; Runtime is O(m log n)
What is a source vertex?
It has no incoming edges and has the highest post number
What is a sink vertex?
It has no outgoing edges and has the lowest post number