Hello, everyone !
If I may add some comments.
N. O'Trealy is right when he says that the best approach is to look
at the mathematical definitions of objects. On the other hand, one
needs to be careful. For instance, the set E of a graph G = (V,E), a
directed graph G = (V,E) and a multigraph G = (V,E) are all different.
For a directed graph, E is a subset of the cartesian product of V.
For an undirected one, E is a subset of all unordered pairs of V.
For a multigraph, E is a submultiset of the cartesian product of V
(multisets are unordered collections of elements with possible
repetition, also sometimes called bags).
Therefore, the degree function is well defined for all three kinds
of graphs, but has different meaning. A vertex having only a
self-loop in a directed graph will have in-degree 1, out-degree 1 and
degree 2. For undirected graph, in general, we do not define
in- and out-degree, just degree, which would be 2 for a self-loop and
it seems reasonable to set the in- and out-degree both to 2 as well.
As for multigraphs (which may be directed or not), the in-, out- and
normal degree are obtained with the definitions:
in_degree(v) = #{ u | (u,v) \in E}
out_degree(v) = #{ u | (v,u) \in E}
degree(v) = in_degree(v) + out_degree(v) if directed,
otherwise degree(v) = #{ u | {u,v} \in E}.
I guess I did not bring much to the discussion, but I wanted to
underline
that 'directed' vs 'undirected' is distinguished by forcing elements
of E to
be either couples (ordered) or pairs (unordered), while 'multigraph'
vs 'not
multigraph' is mathematically dstinguished by forcing E to be either a
multiset (or bag) or a regular set.
Alex