Breadth First Search

BFS performs breadth first search on graph with source and target vectors.

Sie verfolgen jetzt diese Einreichung

BFS performs breadth first search on graph with source and target
vectors.
Syntax:

[searchNodes,iterations] = bfs(source,target,names,startNode)
[searchNodes,iterations] = bfs(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 bfs iteration summary.

Example 01:

s = {'A','A','A','B','B','C'};
t = {'B','C','D','E','F','G'};
[searchNodes,iterations] = bfs(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] = bfs(s,t,names,'A')

Example 03:

s = [1 1 1 2 2 3];
t = [2 3 4 5 6 7];
[searchNodes,iterations] = bfs(s,t,1)

Coded by Ali Asghar Manjotho
Lecturer, CSE-MUET
Email: ali.manjotho.ali@gmail.com

Zitieren als

Ali Asghar Manjotho (2026). Breadth First Search (https://de.mathworks.com/matlabcentral/fileexchange/58584-breadth-first-search), MATLAB Central File Exchange. Abgerufen .

Kategorien

Mehr zu Graph and Network Algorithms finden Sie in Help Center und MATLAB Answers

Allgemeine Informationen

Kompatibilität der MATLAB-Version

  • Kompatibel mit allen Versionen

Plattform-Kompatibilität

  • Windows
  • macOS
  • Linux
Version Veröffentlicht Versionshinweise Action
1.0.0.0