// compute the degree of v (with hove many vertexes current vertex is connected public static int Degree(Graph G, int v) { int degree = 0; foreach (var vertex in G.Adj(v)) { degree += 1; } return degree; }
// compute maximum degree public static int MaxDegree(Graph G) { int max = 0; for (int v = 0; v < G.V; v++) { if (Graph.Degree(G, v) > max) { max = Graph.Degree(G, v); } } return max; }
// compute average degree public static int AvgDegree(Graph G) { return 2 * G.E / G.V; }
// count self-loops public static int numberOfSelfLoops(Graph G) { int count = 0; for (int v = 0; v < G.V; v++) { foreach (int w in G.Adj(v)) { if (v == w) { count++; } } } return count / 2; // each edge counted twice }