Search code examples
algorithmgraphgraph-algorithmdiscrete-mathematicsjgrapht

Edges number in a subgraph counted by vertice degree


I have a subgraph that is only identified as a set of vertices with known degree.

I would like to know how many edges are in this subgraph. Is there a method to count this?

Mind that not every edge is in the subgraph. There are edges that connect vertice in the subgraph and vertice outside of it so it can't be counted simply as a sum of vertice's degrees divided by 2.

If this is of any help I'm using JGraphT.


Solution

  • Q: Is there a method to count this?

    Only with the set of vertices with known degree - unfortunately not. Consider this simple counter-example: a complete subgraph with 3 vertices would be represented with 3 vertices of degree 2 (let's assume that this is a strongly connected component), so in this case number of edges in the subgraph is 3.

    However, if you have 3 vertices of degree 2 that are not all mutually connected (e.g., A and B and A and C are connected, but B and C are not), and the vertices B and C are still of degree 2 because of the edges with other vertices that are not in the subgraph the answer would be 2. Thus, for the same input you can have two different outputs which indicates that you need some additional data.