Solution:
A graph G is a pair of sets. The first set, V, is a set of vertices. The second set, E,
is a set of edges. An edges is a pair of vertices e.g., (i,j). A graph represents a
binary relationship between vertices.
Edges in a graph can be *weighted* or *unweighted*, and *directed* or *undirected*.
-
Define the following terms in relation to graphs:
-
Weighted
-
Directed
-
Connected
Solution:
A graph is *weighted* if its edges have weights or costs. A social network,
for instance, is unlikely to be weighted, while a map probably is
(where the weight might represent distance, difficulty of traveling, etc.).
A graph is *directed* if the edges represent assymmetric relationships between
vertices. If the relationship is symmetric, the graph is *undirected*.
An undirected graph is *connected* if, for each vertex in the graph, there is
a path to every other vertex.
-
What is an Adjacency List?
Solution:
An adjacency list is a way of implementing a Graph, where vertices are
stored together with their list of neighbors or edges. In pseudocode, we assumed
the vertices were numbered 1,..., n and drew the adjacency list as an array of
(vertex, List of vertices) pairs.
In the lab, we implemented an adjancy List as a Dictionary, with string keys
representing vertices, and the values vector<Edge> representing the edges incident
to the vertex key.
Consider the following graph:
A --- B -- C
| \ / |
D -- E ---- F
Perform BFS to find a path from A to F. (in lab we called this function
shortestLengthPathBFS
) What path gets returned?