Question about how to get dfs() working ?


E.g. I wonder if it is possible to compute the “layer” of all vertices of a directed tree using igraph::dfs(). Without using other functions that implicitly traverse the graph such as shortst_paths(), distances(), degree(), layout_with_sugiyama().

The layer of a vertex is (recursively) defined as

  • equal to zero if there are no outgoing edges and
  • otherwise the largest layer among the successors, plus 1.

It is straightforward to code this manually, but the native dfs() is obviously much faster.