2

Is there a known algorithm for checking whether a graph is a complete digraph?

Ideally, I'd like to find a ready-to-use method from JGraphT Java library.

Alternatively, I've found the following answer regarding completeness check of an undirected graph. Would the following modification work for checking completeness of a directed graph?

  1. check that number of directed edges in the graph is n(n-1)
  2. check that each vertice is directly connected to exactly n-1 distinct vertices

If I don't miss anything and these conditions are sufficient I could implement these checks by myself, but I'd prefer to use existing implementation from the library if possible.

gregs
  • 115
  • 1
  • 8

2 Answers2

2

Can you try this JGraphT method?

GraphTests#isComplete

it says that it checks for digraphs as well.

Test whether a graph is complete. A complete undirected graph is a simple graph in which every pair of distinct vertices is connected by a unique edge. A complete directed graph is a directed graph in which every pair of distinct vertices is connected by a pair of unique edges (one in each direction).

buræquete
  • 14,226
  • 4
  • 44
  • 89
  • 1
    Thanks, that's exactly what I was looking for! BTW I checked that this method actually checks if the number of edges is equal to n(n-1) assuming the graph is simple. – gregs Jul 23 '19 at 08:33
1

If your graph doesn't have more than one edge going from and to the same nodes that is the easiest way to do it.

You cannot have a graph that is not complete and has that many (n*(n-1)) edge without duplicated edges.

Romil Patel
  • 12,879
  • 7
  • 47
  • 76
Tony Barletta
  • 375
  • 1
  • 8