graphtraverse
(Removed) Traverse graph by following adjacent nodes
graphtraverse
has been removed. Use bfsearch
or dfsearch
instead. For details, see
Version History.
Syntax
[
disc
, pred
, closed
] = graphtraverse(G
, S
)
[...] = graphtraverse(G
, S
, ...'Depth', DepthValue
, ...)
[...] = graphtraverse(G
, S
, ...'Directed', DirectedValue
, ...)
[...] = graphtraverse(G
, S
, ...'Method', MethodValue
, ...)
Arguments
G
| N-by-N adjacency matrix that represents a directed graph. Nonzero
entries in matrix G indicate the presence
of an edge. |
S | Integer that indicates the source node in graph
G . |
DepthValue | Integer that indicates a node in graph
G that specifies the depth of the
search. Default is Inf (infinity). |
DirectedValue | Property that indicates whether graph
G is directed or undirected. Enter
false for an undirected graph. This results
in the upper triangle of the adjacency matrix being ignored. Default
is true . |
MethodValue | Character vector or string that specifies the algorithm used to
traverse the graph. Choices are:
|
Description
Tip
For introductory information on graph theory functions, see Graph Theory Functions.
[
traverses graph disc
, pred
, closed
] = graphtraverse(G
, S
)G
starting from the node indicated by integer
S
. G
is an N-by-N adjacency matrix
that represents a directed graph. Nonzero entries in matrix G
indicate the presence of an edge. disc
is a vector of node
indices in the order in which they are discovered. pred
is a
vector of predecessor node indices (listed in the order of the node indices) of the
resulting spanning tree. closed
is a vector of node indices
in the order in which they are closed.
[...] =
graphtraverse(
calls
G
, S
, ...'PropertyName
',
PropertyValue
, ...)graphtraverse
with optional properties that use property
name/property value pairs. You can specify one or more properties in any order. Each
PropertyName
must be enclosed in single quotes and is
case insensitive. These property name/property value pairs are as follows:
[...] = graphtraverse(
specifies the depth of the search. G
, S
, ...'Depth', DepthValue
, ...)DepthValue
is an integer
indicating a node in graph G
. Default is
Inf
(infinity). The 'Depth'
name-value
argument is no longer supported for the 'DFS'
method.
[...] = graphtraverse(
indicates whether the graph is directed or undirected. Set
G
, S
, ...'Directed', DirectedValue
, ...)DirectedValue
to false
for an
undirected graph. This results in the upper triangle of the adjacency matrix being
ignored. Default is true
.
[...] = graphtraverse(
lets you specify the algorithm used to traverse the graph. Choices are:G
, S
, ...'Method', MethodValue
, ...)
'BFS'
— Breadth-first search. Time complexity isO(N+E)
, whereN
andE
are number of nodes and edges respectively.'DFS'
— Default algorithm. Depth-first search. Time complexity isO(N+E)
, whereN
andE
are number of nodes and edges respectively. The'Depth'
name-value argument is no longer supported for the'DFS'
method.
References
[1] Sedgewick, R., (2002). Algorithms in C++, Part 5 Graph Algorithms (Addison-Wesley).
[2] Siek, J.G., Lee, L-Q, and Lumsdaine, A. (2002). The Boost Graph Library User Guide and Reference Manual, (Upper Saddle River, NJ:Pearson Education).