count_reachable: Count reachable vertices

View source: R/structural-properties.R

count_reachableR Documentation

Count reachable vertices

Description

[Experimental]

Usage

count_reachable(graph, mode = c("out", "in", "all", "total"))

Arguments

graph

The input graph.

mode

Character constant, defines how edge directions are considered in directed graphs. "out" counts vertices reachable via outgoing edges, "in" counts vertices from which the current vertex is reachable via incoming edges, "all" or "total" ignores edge directions. This parameter is ignored for undirected graphs.

Details

Counts the number of vertices reachable from each vertex in the graph.

For each vertex in the graph, this function counts how many vertices are reachable from it, including the vertex itself. A vertex is reachable from another if there is a directed path between them. For undirected graphs, two vertices are reachable from each other if they are in the same connected component.

Value

An integer vector of length vcount(graph). The i-th element is the number of vertices reachable from vertex i (including vertex i itself).

Related documentation in the C library

count_reachable()

Author(s)

Gabor Csardi csardi.gabor@gmail.com

See Also

components(), subcomponent(), is_connected()

Connected components articulation_points(), biconnected_components(), component_distribution(), decompose(), is_biconnected()

Examples


# In a directed path graph, the reachability depends on direction
g <- make_graph(~ 1 -+ 2 -+ 3 -+ 4 -+ 5)
count_reachable(g, mode = "out")
count_reachable(g, mode = "in")

# In an undirected graph, reachability is the same in all directions
g2 <- make_graph(~ 1 - 2 - 3 - 4 - 5)
count_reachable(g2, mode = "out")

# A graph with multiple components
g3 <- make_graph(~ 1 - 2 - 3, 4 - 5, 6)
count_reachable(g3, mode = "all")


igraph documentation built on April 21, 2026, 5:06 p.m.