Question
In the context of this exercise, can two vertices have more than one edge connecting them?
Answer
In the Codecademy lessons, graphs will be implemented such that two vertices can only have up to one undirected edge connecting them, for an undirected graph, or two directed edges connecting them, for a directed graph.
One way to think of this is that, for an undirected graph, two edges are either connected or not connected. So there are only either 0 edges or 1 edge between them. We may represent this for two vertices A
and B
like so, where <->
is the undirected edge between them:
A <-> B
For directed graphs, we essentially now have that two edges are either connected or not connected, AND, that they are either directed in one direction or the other. We can visualize the two possible directed edges between two vertices A
and B
with ->
signifying the directedness of a vertex to another, as:
A -> B
or
B -> A