bfs

fun bfs(startNodes: List<T>, target: T? = null, reset: Boolean = true)

Performs a Breadth-First Search, which finds the shortest path from the starting node to all other nodes, assuming the graph is unweighted (all edges have a weight of 1.0) It stores results that can be retrieved with the following functions:

  • depth()

  • currentVisitedNodes()

  • visitedNodes()

  • finalPath()

  • foundTarget()

  • distanceTo(node: T)

  • maxDistance()

  • furthestNode()

Parameters

startNodes

A list of starting nodes for the BFS traversal.

target

An optional target node. If specified, the search will stop once the target is found, flag the target as found so that foundTarget() returns true, and store the path to the target node for use in visualization.

reset

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

Throws

IllegalStateException

If any of the starting nodes or the target node is not found in the graph.


fun bfs(startNode: T, target: T? = null, reset: Boolean = true)

Overload of fun bfs(startNodes: List, target: T?, reset: Boolean) that accepts a single starting node istead of a list