DFS(graph, source, target)

Implementation of Depth-first Search.

new DFS(graph, source, target)

Constructs a DFS algorithm object.

Parameters:
Name Type Default Description
graph Graph null

The graph.

source Number

The node index of the source node.

target Number

The node index of the target node.

Author:

Members

found :Boolean

Whether the search was successful or not.

Default Value:
  • false

nullable graph :Graph

The graph.

Default Value:
  • null

source :Number

The node index of the source node.

Default Value:
  • - 1

target :Number

The node index of the target node.

Default Value:
  • - 1

Methods

clear() → {DFS}

Clears the internal state of the object. A new search is now possible.

Returns:
DFS -

A reference to this DFS object.

getPath() → {Array.<Number>}

Returns the shortest path from the source to the target node as an array of node indices.

Returns:
Array.<Number> -

The shortest path.

getSearchTree() → {Array.<Edge>}

Returns the search tree of the algorithm as an array of edges.

Returns:
Array.<Edge> -

The search tree.

Executes the graph search. If the search was successful, DFS#found is set to true.

Returns:
DFS -

A reference to this DFS object.