Vertex descendants subgraph
You are looking for VertexOutComponent
.
VertexOutComponent[g, 4]
gives you the successors of 4
. Use Subgraph
to get an actual graph out of those. With HighlightGraph
, you can also use a subgraph, it will highlight both vertices and edges: HighlightGraph[g, Subgraph[g, VertexOutComponent[g, 4]]]
.
For visualizing the graph, use GraphLayout -> "LayeredDigraphEmbedding"
, which will place the root at the topmost position. Some other tree layouts have a "RootVertex"
suboptions to achieve this (e.g. for undirected where anything can be the "root").
You could also do for example the following for recovering the result as a graph:
HighlightGraph[g, s = Last@Reap@BreadthFirstScan[g, 3, {"FrontierEdge" -> Sow}]]
Graph@@s