# NOT RUN {
# Create a graph containing two balanced trees
graph <-
create_graph() %>%
add_balanced_tree(2, 2) %>%
add_balanced_tree(3, 2)
# Perform a breadth-first search of the graph,
# beginning at the root node `1` (the default
# `direction = "all"` doesn't take edge
# direction into account)
graph %>% do_bfs(1)
#> [1] 1 2 3 4 5 6 7 8 9 10 11 12 13
#> [14] 14 15 16 17 18 19 20
# If not specifying a starting node, the function
# will begin the search from a random node
graph %>% do_bfs()
#> [1] 6 3 1 7 2 4 5 8 9 10 11 12 13
#> [14] 14 15 16 17 18 19 20
# It's also possible to perform bfs while
# taking into account edge direction; using
# `direction = "in"` causes the bfs routine to
# visit nodes along inward edges
graph %>% do_bfs(1, "in")
#> [1] 1 2 3 4 5 6 7 8 9 10 11 12 13
#> [14] 14 15 16 17 18 19 20
# Using `direction = "out"` results in the bfs
# moving along solely outward edges
graph %>% do_bfs(1, "out")
#> [1] 1 2 3 4 5 6 7 8 9 10 11 12 13
#> [14] 14 15 16 17 18 19 20
# }
Run the code above in your browser using DataLab