Class DFS
Implements Depth First Search algorithm for graph traversal.
Inheritance
Inherited Members
Namespace: AlgorithmsAndDataStructures.Algorithms.GraphTraversal
Assembly: AlgorithmsAndDataStructures.dll
Syntax
public class DFS
Methods
| Improve this Doc View SourceDFS_Iterative<TValue>(GraphNode<TValue>)
An iterative version of Depth First Search algorithm for traversing a graph that might have cycles.
Declaration
public static List<GraphNode<TValue>> DFS_Iterative<TValue>(GraphNode<TValue> startNode)
Parameters
Type | Name | Description |
---|---|---|
GraphNode<TValue> | startNode | A node in the graph from which traversal starts. |
Returns
Type | Description |
---|---|
System.Collections.Generic.List<GraphNode<TValue>> | A sequence of all graph nodes, put into a DFS ordering. |
Type Parameters
Name | Description |
---|---|
TValue | Type of the values stored in graph nodes. |
Remarks
A graph can have many DFS orderings. Each ordering depends on (i) the start node, and (ii) the order by which each node's adjacent nodes are visited.
DFS_Recursive<TValue>(GraphNode<TValue>, List<GraphNode<TValue>>)
A recursive version of Depth First Search algorithm for traversing a graph that might have cycles.
Declaration
public static void DFS_Recursive<TValue>(GraphNode<TValue> startNode, List<GraphNode<TValue>> dfsOrdering)
Parameters
Type | Name | Description |
---|---|---|
GraphNode<TValue> | startNode | A node in the graph from which traversal starts. |
System.Collections.Generic.List<GraphNode<TValue>> | dfsOrdering | A sequence of all graph nodes, put into a DFS ordering |
Type Parameters
Name | Description |
---|---|
TValue | Type of the values stored in graph nodes. |
Remarks
A graph can have many DFS orderings. Each ordering depends on (i) the start node, and (ii) the order by which each node's adjacent nodes are visited.