CS6515_Exam2 Flashcards
If you are given an UNDIRECTED graph you can only find ________ _________?
connected components
If you are given a DIRECTED graph, you can only find ________ ________ _______?
strongly connected components
When given an undirected graph, one of the best things to do first is look for strongly connected components? (T/F)
False. The concept of strongly connected components doesn’t exist for undirected graphs.
In the 06/15 Office Hours, Joves’ mentions big penalties will be applied for things like this.
How do you find sources and sinks on an undirected graph?
Trick question. Sources and sinks don’t exist on undirected graphs. They only make sense in the context of directed graphs.
What are some important properties/characteristics of Directed Acyclic Graphs (DAGs)?
Hint: DPV textbook mentions there are 3 of them
- A directed graph has a cycle if and only if its DFS reveals a back edge
- In a DAG, every edge leads to a vertex with a lower post number
- Every DAG has at least once source and at least one sink
What is a source node?
A node with in-degree of 0, i.e. no incoming edges
What is a sink node?
A node with out-degree of 0, i.e. no outgoing edges
If your graph has no weights, then you can’t calculate a minimum spanning tree? (T/F) Why or why not?
This is really a trick question, the answer can be True or False, depending on perspective. In reality, MSTs only really make sense on a weighted graph. For an unweighted graph, the concept of “minimum” isn’t well-posed, so technically ANY spanning tree on an unweighted graph is minimal, but it’s essentially a useless definition (consider that it would also be a minimum spanning tree == maximal spanning tree in the unweighted case; a distinction without a difference).
What are the 9 algorithms (at minimum) that we are allowed to use as black-boxes for HW/Exams?
- Dijkstra’s
- BFS
- DFS
- Explore (subroutine of DFS, but allowed to use as standalone algo)
- Strongly connected components (SCC) [Joves’ mentions this one as being especially important]
- 2SAT Algorithm
- Kruskal’s Algorithm
- Prim’s MST Algorithm
- Anything else mentioned in the Lectures and/or Textbook
Source: 06/15 Office Hours
We should NEVER modify the black-box graph algorithms for the HW/Exam? (T/F)
True. Joves’ emphasizes this multiple times in 06/15 Office Hours.
The strongly connected components algorithm is analogous to what other algorithm?
SCC uses multiple runs of DFS, with some modifications to the input and output variables.
DFS/BFS do NOT consider edge weights? (T/F)
True.
What is the runtime of DFS/BFS?
O(n + m), i.e. one of the fastest options we have, but with the caveat that if we need to consider edge weights, then that adds additional time complexity.
What are the runtimes of all the key black-box graph algorithms?
- BFS: O(n + m)
- DFS: O(n + m)
- Dijkstra’s: O((n + m) * log n)
- Explore: O(m) if part of DFS; O(n + m) if standalone
- Topological Sort : O(n + m)
- SCC: O(n + m)
- 2-SAT: O(n + m)
- Kruskal’s MST Algo: O(m log n)
- Prim’s MST Algo: O(m log n)
- Ford-Fulkerson: O(mC)
- Edmonds-Karp: O(nm^2)
- Bellman-Ford: O(nm)
- Floyd-Warshall: O(n^3)
We should ALWAYS use adjacency list representation for graphs in this class, and NEVER use adjacency matrices? (T/F)
True. Joves’ mentions in office hours that the gains from using the matrix form are minimal, and if implemented incorrectly can cause runtimes to massively explode.
What is the runtime to index into a vertex in a graph?
For this class, we assume O(1)
What is the runtime to find an edge in a graph? Why?
O(m). Because we have to scan over the edges in the adjacency list up to m edges.
For exams, we need to explicitly define that n = |V| and/or that m = |E|? (T/F)
False. Joves’ says in 06/15 Office Hours we can just assume this as understood without explicitly writing down.
To traverse a graph or find all edges, what is the runtime?
O(n + m)
Why is traversing a graph or finding all the edges O(n + m) and not O(nm)?
Because if it was O(nm), that would imply that EVERY vertex is connected to EVERY edge. This is obviously not the case. Also, the runtime for BFS/DFS is O(n + m), which allows us to traverse all the edges in that amount of time.
Joves’ mentions a lot of students make this mistake.
As mentioned in lectures/OH/textbook, what is “Property 1” of trees?
Removing a cycle edge cannot disconnect a graph.
As mentioned in lectures/OH/textbook, what is “Property 2” of trees?
A tree on n nodes has n - 1 edges (i.e. the definition of a tree)
As mentioned in lectures/OH/textbook, what is “Property 3” of trees?
Any connected, undirected graph G = (V, E) with m = n - 1 edges is a tree. (This is the converse of Property 2.)
As mentioned in lectures/OH/textbook, what is “Property 4” of trees?
An undirected graph is a tree if any only if there is a unique path between any pair of nodes.
If there is more than one path between any pair of nodes, then there is a cycle
If there is no path between any pair of nodes, then it is not connected.