Graphs Flashcards
Which is more general, tree or graph?
A graph which can have any combinations of nodes & edges
What two classes of graphs are there?
Undirected and directed. Directed graphs have arrow lines as opposed to plane lines.
What is the terminology for adjacent nodes for both types of graphs?
Neighbor nodes
Which node does the target and source of a directed edge lie, respectively?
predecessor, successor
What is an example of a cyclic path and acyclic path?
1→2→3→1 : cyclic
1→2→3→4: acyclic
1→1: cyclic
What does DAG stand for?
Directed acyclic graph
What is the name of a undirected/directed graph where all nodes neighbor every other node
A complete graph
What is an edge called if it is assigned a number?
A weighted edge, which could represent length
When is a graph strongly connected?
If every node is reachable with direction
When is a graph weakly connected?
If every node is reachable regardless of direction
If all nodes can be reached from a set of nodes how is this represented in java?
This can be represented as an array or list of root nodes
What condition must bee satisfied in topological numbering?
If the order is u,v then u must always occur before v in any path
What nodes are always in the first positions in topological ordering?
nodes with an in-number of zero
What is the difference between in-degree, out-degree and degree?
in-deg: edges going in
out-deg: edges going out
deg: all in & out edges
What two data structures are best suited for a dfs & bfs respectively?
dfs: stack
bfs: queue, which holds the nodes to be visited at each level
What is the distance of a graph?
The number of edges from node A to node B
How does an adjacency list represent the graph?
It lists each vertices on the left and all of it’s adjacent nodes on the right
What is the complexity to look for weather a node is adjacent?
O(V), because the vertex could be neighbors with every other node, unless the graph is sparse (doesn’t have many edges)
How does the adjacency list differ from the adjacency matrix?
The list of neighboring vertices is replaced by a list of 1 & 0 creating a 2x2 matrix
Why is an adjacency list more efficient for sparse graphs, while an adjacency matrix is not?
Because the size of the matrix is O(V^2), which is unnecessary since a list wouldn’t have to include the 0’s
For an 2D array implementation of an adjacency matrix what is the complexity for a an edge lookup?
O(1)
What is the size of a graph?
O(V+E)
What is a method where all nodes are visited in an arbitrary order?
graph traversal
What is the general idea of a breadth-first-search?
traversal that visits a starting vertex, then all vertices of distance 1 from that vertex, then of distance 2, and so on, without revisiting a vertex