Depth First Search
DFS performs depth first search on graph with source and target vectors.
Syntax:
[searchNodes,iterations] = dfs(source,target,names,startNode)
[searchNodes,iterations] = dfs(source,target,startNode)
Inputs:
source = Vector or cell array containing starting node of each of the edge.
target = Vector or cell array containing ending node of each of the edge.
names = Cell array containing string names of each of the node.
startNode = Initial node in the graph.
Outputs:
path = Cell array containing search path.
iterations = Table containing dfs iteration summary.
Example 01:
s = {'A','A','A','B','B','C'};
t = {'B','C','D','E','F','G'};
[searchNodes,iterations] = dfs(s,t,'A')
Example 02:
s = [1 1 1 2 2 3];
t = [2 3 4 5 6 7];
names = {'A','B','C','D','E','F','G'};
[searchNodes,iterations] = dfs(s,t,names,'A')
Example 03:
s = [1 1 1 2 2 3];
t = [2 3 4 5 6 7];
[searchNodes,iterations] = dfs(s,t,1)
Coded by Ali Asghar Manjotho
Lecturer, CSE-MUET
Email: ali.manjotho.ali@gmail.com
Cite As
Ali Asghar Manjotho (2024). Depth First Search (https://www.mathworks.com/matlabcentral/fileexchange/58585-depth-first-search), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Platform Compatibility
Windows macOS LinuxCategories
Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.
Version | Published | Release Notes | |
---|---|---|---|
1.0.0.0 |