dfs

fun dfs(startNode: T, reset: Boolean = true)

Performs a Depth-First Search, which finds all nodes that's reachable from the starting node. It stores results that can be retrieved with the following functions:

  • depth()

  • currentVisitedNodes()

  • visitedNodes()

  • distanceTo(node: T) Note: returns the depth of the node in the DFS tree, not the shortest distance.

  • maxDistance() (based on DFS tree depth)

  • furthestNode() (based on DFS tree depth)

Parameters

startNode

The starting node for the DFS traversal.

reset

A boolean indicating whether to reset the previous search results. If set to false, previously visited nodes will not be visited again.

Throws

If the starting node is not found in the graph.