Let be an undirected graph with
and
. For Problems 5, 6, and 7, give two answers: one if
is represented as an adjacency list and another if
is represented as an adjacency matrix.
What is the runtime of iterating over all edges?
Suppose and
are nodes in
and node
has degree
. What is the runtime of determining whether there is an edge from
to
?
What is the asymptotic storage space required to represent ?
Suppose G is connected. What are the smallest and largest possible values of ? Considering this and your answer to the prior question, under what circumstances would you be likely to prefer an adjacency list over an adjacency matrix, and vice versa?
Suppose a directed graph H has nodes and is strongly connected. What’s the smallest possible value of
?
How might you use graphs to aid in contact tracing (i.e., to help track who may be infected, given a set of people who are known to have a contagious disease)?