# Counting the number of edges between two graph partitions

Consider the following:

g = RandomGraph[WattsStrogatzGraphDistribution[1000, 0.1, 5]]
comm = FindGraphPartition[g, 2];
CommunityGraphPlot[g, comm]


FindGraphPartition[g,2] will find a partition of vertices such that the number of edges having endpoints in different parts is minimized. How can I get Mathematica to tell me the number of edges that connect these two groups? It seems like something I should be able to get at easily, but looking through the documentation I just can't find anything.

Thank you!

If you just need the number of edges, you can use

EdgeCount[g, UndirectedEdge[Alternatives @@ comm[[1]], Alternatives @@ comm[[2]]]]

 376


If you need the list of edges:

el = EdgeList[g, UndirectedEdge[Alternatives @@ comm[[1]], Alternatives @@ comm[[2]]]]

Length @ el

376

Short[el, 5]