示例#1
0
        // 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;
        }
示例#2
0
        // 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;
        }
示例#3
0
 // compute average degree
 public static int AvgDegree(Graph G)
 {
     return 2 * G.E / G.V;
 }
示例#4
0
        // 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
        }