Americas
Europe
Q42E
Expert-verifiedDevise an algorithm for constructing the spanning forest of a graph based on breadth-first searching.
By using the breadth-first search I can construct the spanning forest.
A spanning tree of a simple graph G is a subgraph of G that is a tree and which contains all vertices of G.
A tree is an undirected graph that is connected and does not contain any single circuit. And a tree with n vertices has \({\bf{n - 1}}\) edges.
In breadth-first search first, choose a root. Add all edges incident to the root. Then each of the vertices at level 1, add all edges incident with ta vertex not included in the tree yet. And repeat until all vertices were added to the tree.
Let G be an undirected graph having vertices\({\bf{V = \{ }}{{\bf{v}}_{\bf{1}}}{\bf{,}}{{\bf{v}}_{\bf{2}}}{\bf{,}}......{\bf{,}}{{\bf{v}}_{\bf{n}}}{\bf{\} }}\).
\(\begin{array}{c}{\bf{T = G}}\\{\bf{V = \{ }}\,{{\bf{v}}_{\bf{1}}}{\bf{,}}{{\bf{v}}_{\bf{2}}}{\bf{,}}......{\bf{,}}{{\bf{v}}_{\bf{n}}}{\bf{\} }}\\{\bf{L = \{ }}\,{{\bf{v}}_{\bf{1}}}{\bf{\} }}\\{\bf{M = \{ }}\,{{\bf{v}}_{\bf{1}}}{\bf{\} }}\end{array}\)
\(\begin{array}{c}{\bf{while}}\,{\bf{L}} \ne {\bf{M}}\\{\bf{if}}\,{\bf{M = }}\phi \,{\bf{then}}\\{\bf{for}}\,{\bf{j = 1}}\,\,{\bf{ton}}\\{\bf{if}}\,{{\bf{v}}_{\bf{j}}} \notin {\bf{L}}\,{\bf{then}}\end{array}\)
\(\begin{array}{c}{\bf{L = L}} \cup {\bf{\{ }}\,{{\bf{v}}_{\bf{j}}}{\bf{\} }}\\{\bf{M = M}} \cup {\bf{\{ }}\,{{\bf{v}}_{\bf{j}}}{\bf{\} }}\\{\bf{N = }}\phi \end{array}\)
For every vertex v in M
\({\bf{for}}\,{\bf{j = 1}}\,\,{\bf{ton}}\)
If \({\bf{(}}{{\bf{v}}_{\bf{i}}}{\bf{,}}{{\bf{v}}_{\bf{j}}}{\bf{)}}\) is an edge in G then
\({\bf{if}}\,{{\bf{v}}_{\bf{j}}} \in {\bf{L}}\,{\bf{then}}\)
Remove the edge \({\bf{(}}{{\bf{v}}_{\bf{i}}}{\bf{,}}{{\bf{v}}_{\bf{j}}}{\bf{)}}\) from T
Remove the edge \({\bf{(}}{{\bf{v}}_{\bf{i}}}{\bf{,}}{{\bf{v}}_{\bf{j}}}{\bf{)}}\) from G
Else
Remove the edge from the graph G
\(\begin{array}{c}{\bf{L = L}} \cup {\bf{\{ }}\,{{\bf{v}}_{\bf{j}}}{\bf{\} }}\\{\bf{N = N}} \cup {\bf{\{ }}\,{{\bf{v}}_{\bf{j}}}{\bf{\} }}\\{\bf{M = N}}\\{\bf{return}}\,\,{\bf{T}}\end{array}\)
Therefore, this is the require algorithm.
94% of StudySmarter users get better grades.
Sign up for free