Main Content

graphtraverse

(To be removed) Traverse graph by following adjacent nodes

graphtraverse will be removed in a future release. Use bfsearch or dfsearch instead. For details, see Compatibility Considerations.

Syntax

[disc, pred, closed] = graphtraverse(GS)
[...] = graphtraverse(GS, ...'Depth', DepthValue, ...)
[...] = graphtraverse(GS, ...'Directed', DirectedValue, ...)
[...] = graphtraverse(GS, ...'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.
SInteger that indicates the source node in graph G.
DepthValueInteger that indicates a node in graph G that specifies the depth of the search. Default is Inf (infinity).
DirectedValueProperty 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.
MethodValueCharacter vector or string that specifies the algorithm used to traverse the graph. Choices are:
  • 'BFS' — Breadth-first search. Time complexity is O(N+E), where N and E are number of nodes and edges respectively.

  • 'DFS' — Default algorithm. Depth-first search. Time complexity is O(N+E), where N and E are number of nodes and edges respectively.

Description

Tip

For introductory information on graph theory functions, see Graph Theory Functions.

[disc, pred, closed] = graphtraverse(GS) traverses graph 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(GS, ...'PropertyName', PropertyValue, ...) calls 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(GS, ...'Depth', DepthValue, ...) specifies the depth of the search. 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(GS, ...'Directed', DirectedValue, ...) indicates whether the graph is directed or undirected. Set DirectedValue to false for an undirected graph. This results in the upper triangle of the adjacency matrix being ignored. Default is true.

[...] = graphtraverse(GS, ...'Method', MethodValue, ...) lets you specify the algorithm used to traverse the graph. Choices are:

  • 'BFS' — Breadth-first search. Time complexity is O(N+E), where N and E are number of nodes and edges respectively.

  • 'DFS' — Default algorithm. Depth-first search. Time complexity is O(N+E), where N and E 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).

Version History

Introduced in R2006b

expand all

Warns starting in R2022a

Behavior changed in R2021b

Behavior changed in R2021b

See Also

|