Skip to content

eles.depthFirstSearch(rootOrOptions?, visitOrDirected?, directed?)

eles.depthFirstSearch — Collection > Algorithms > Search and shortest paths. Cytoscape.js signatures, parameters and return contract.

eles.depthFirstSearch — Collection › Algorithms › Search and shortest paths

Preview · Collection › Algorithms › Search and shortest paths

Read in the complete API reference · All API members

// Depth-first search over this collection's subgraph
eles.depthFirstSearch(rootOrOptions?: SearchOptions | Collection<any, any, any> | undefined, visitOrDirected?: boolean | SearchVisitFn | undefined, directed?: boolean | undefined): SearchResult

Depth-first search over this collection's subgraph. It shares the root, callback, direction and result contract of breadthFirstSearch, but explores the most recently discovered branch first.

Parameters
NameDescription
rootOrOptions: SearchOptions | Collection<any, any, any> | undefined?

Starting node or an object containing root, visit and directed.

visitOrDirected: boolean | SearchVisitFn | undefined?

Visit callback, or a direction flag when no callback is needed.

directed: boolean | undefined?

True to follow outgoing edges only; defaults to false.

Returns SearchResult

{ path, found }; path contains visited nodes and their discovery edges in depth-first callback order

Example

const result = eles.depthFirstSearch({ root: cy.getElementById('a'), directed: true });
console.log(result.path.nodes().length); // 3

Example graph and handle setup

Throws

if a root is given as a selector string

Also spelled eles.dfs.