// Depth-first search over this collection's subgraph
eles.depthFirstSearch(rootOrOptions?: SearchOptions | Collection<any, any, any> | undefined, visitOrDirected?: boolean | SearchVisitFn | undefined, directed?: boolean | undefined): SearchResultDepth-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.
| Name | Description |
|---|---|
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. |
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); // 3if a root is given as a selector string
Also spelled eles.dfs.