View source: R/5-grafos-arbol.R
bfs_tree | R Documentation |
Computation of the breadth-first tree search in an undirected graph.
bfs_tree(g, r)
g |
Graph |
r |
Root: Starting vertex growing the tree. |
Starting from a root vertex, the tree is grown by adding neighbors of the first vertex added to the tree until no more neighbors are left; then it passes to another vertex with neighbors outside the tree. In this way, the tree has few levels and many branches and leaves.
A directed spanning subgraph of g containing the edges of the BFS tree.
Cesar Asensio
g <- make_graph("Frucht")
T <- bfs_tree(g, 2) # Root at v = 2
z <- layout_with_gem(g)
plot(g, layout = z, main = "Breadth-first search tree")
plot(T, layout = z, add = TRUE, edge.color = "cyan4", edge.width = 2)
plot(T, layout = layout_as_tree(T))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.