bfs {RBGL} | R Documentation

## Breadth and Depth-first search

### Description

These functions return information on graph traversal by breadth and depth first search using routines from the BOOST library.

### Usage

    bfs(object, node, checkConn=TRUE)
    dfs(object, node, checkConn=TRUE)

### Arguments

`object` | instance of class graph from Bioconductor graph class
`node` | node name where search starts; defaults to the node in first position in the node vector.
`checkConn` | logical for backwards compatibility; this parameter has no effect as of RBGL 1.7.9 and will be removed in future versions.

### Details

These two functions are interfaces to the BOOST graph library functions for breadth first and depth first search. Both methods handle unconnected graphs by applying the algorithms over the connected components.

Cormen et al note (p 542) that `results of depth-first search may depend upon the order in which the vertices are examined ... These different visitation orders tend not to cause problems in practice, as any DFS result can usually be used effectively, with essentially equivalent results'.

### Value

For `bfs` a vector of node indices in order of BFS visit.
For `dfs` a list of two vectors of nodes, with elements `discover` (order of DFS discovery), and `finish` (order of DFS completion).

### Author(s)

VJ Carey <stvjc@channing.harvard.edu>

### Examples

    dd <- fromGXL(file(system.file("XML/bfsex.gxl",package="RBGL"), open="r"))
    bfs(dd, "r", FALSE)
    bfs(dd, "s", TRUE)

    dd2 <- fromGXL(file(system.file("XML/dfsex.gxl",package="RBGL"), open="r"))
    dfs(dd2, "u", FALSE)

[Package RBGL version 1.10.0 Index]