BFS Spanning Tree

BFS Spanning Tree#

This notebook illustrates how to create a spanning tree of a graph with vertex labels consistent with breadth-first search traversal.

%%capture
%run receptor_tools.ipynb
P = graphs.PetersenGraph()
P.show(edge_labels=False)
(BFSVertexList,BFSTree) = P.lex_BFS(tree=True,initial_vertex=0)
BFSTree.show(edge_labels=False)
show(BFSVertexList)
_images/5d8bc20e9650d98d069663d42e0ac6def6234a7d95603b22723ac181d66785d7.png _images/47af9ea47111a2a1334417a6205fdf1a52ff304ba3badf4cfa2d17ca84a85fb2.png
\(\displaystyle \left[0, 1, 4, 5, 2, 6, 3, 9, 7, 8\right]\)
d = dict((v,i) for i, v in enumerate(BFSVertexList))
print(d)
{0: 0, 1: 1, 4: 2, 5: 3, 2: 4, 6: 5, 3: 6, 9: 7, 7: 8, 8: 9}
P2 = P.copy()
P2.relabel(d)
P2 = add_edge_monomials(P2)
P2.show(figsize=6,edge_labels=True)

T2=BFSTree.copy()
T2.relabel(d)
T2 = add_edge_monomials(T2,short_name=True)
T2.show(figsize=6,edge_labels=True)
_images/66ba80ac89067fcca9e6cf19359728cafbef142e3f38fe018abc1e76701ae416.png _images/9154174312278b9b90585c37be156d44eafdf0763c7b5ad048802718860fd98f.png