# Revision history [back]

Let me try something.

sage: g = graphs.PetersenGraph()
sage: t = Graph(g.min_spanning_tree(starting_vertex=1))
sage: g.set_pos(t.layout_tree(tree_root=1))
sage: g.show()


What do you think ?

Let me try something.

sage: g = graphs.PetersenGraph()
sage: t = Graph(g.min_spanning_tree(starting_vertex=1))
sage: g.set_pos(t.layout_tree(tree_root=1))
sage: g.show()


What Oh, damn, this does not work. Maybe some variation could do you think the job ?

Let me try something.

sage: g = graphs.PetersenGraph()
sage: t = Graph(g.min_spanning_tree(starting_vertex=1))
sage: g.set_pos(t.layout_tree(tree_root=1))
sage: g.show()


Oh, damn, this does not work. Maybe some variation could do the job ?

EDIT: here is a refined proposal, using a better spanning tree.

def BFS_custom(G, v):
"""
Perform a BFS and return edges.

Here G is a graph and v a vertex of G.

(Code by Nathann Cohen)
"""
seen = set([v] + G.neighbors(v))
next_layer = [(v, u) for u in G.neighbors(v)]
while next_layer:
for e in next_layer:
yield e
next_next_layer = []
for _, v in next_layer:
for u in G.neighbors(v):
if u in seen:
continue