Skip to main content
added 246 characters in body
Source Link
Szabolcs
  • 236.5k
  • 31
  • 641
  • 1.3k

This list is just the return value of BreadthFirstScan. It has absolutely nothing to do with Sow and Reap.

According to the documentation, it is the list of the predecessors of the BFS tree.

The first element of the list is 2. This means that 2 -> 1 belongs to the tree, where 1 is the first vertex. The second is 5, so 5 -> 2 also belong to the tree (where 2 is the second vertex). And so on. The

The one tricky thing about this representation is that for those vertices that do not have a predecessor, the "predecessor" of the root vertex is given as the same vertex. This is always the case for the root vertex itself—this(the vertex where the search starts), and can happen for vertices that are not scanned at all (in non-connected graphs). The predecessor lists produced from a connected graph is compatible with how TreeGraph works(see below).

You can reconstruct the tree using TreeGraph:

g = GridGraph[{3, 5}, VertexSize -> {5 -> Medium}]

ps = BreadthFirstScan[g, 5]
(* {2, 5, 2, 5, 5, 5, 4, 5, 6, 7, 8, 9, 10, 11, 12} *)

HighlightGraph[g, TreeGraph[VertexList[g], ps], 
 GraphHighlightStyle -> "Thick"]

enter image description here

This list is just the return value of BreadthFirstScan. It has absolutely nothing to do with Sow and Reap.

According to the documentation, it is the list of the predecessors of the BFS tree.

The first element of the list is 2. This means that 2 -> 1 belongs to the tree, where 1 is the first vertex. The second is 5, so 5 -> 2 also belong to the tree (where 2 is the second vertex). And so on. The one tricky thing about this representation is that the "predecessor" of the root vertex is given as the root vertex itself—this is compatible with how TreeGraph works.

You can reconstruct the tree using TreeGraph:

g = GridGraph[{3, 5}, VertexSize -> {5 -> Medium}]

ps = BreadthFirstScan[g, 5]
(* {2, 5, 2, 5, 5, 5, 4, 5, 6, 7, 8, 9, 10, 11, 12} *)

HighlightGraph[g, TreeGraph[VertexList[g], ps], 
 GraphHighlightStyle -> "Thick"]

enter image description here

This list is just the return value of BreadthFirstScan. It has absolutely nothing to do with Sow and Reap.

According to the documentation, it is the list of the predecessors of the BFS tree.

The first element of the list is 2. This means that 2 -> 1 belongs to the tree, where 1 is the first vertex. The second is 5, so 5 -> 2 also belong to the tree (where 2 is the second vertex). And so on.

The one tricky thing about this representation is that for those vertices that do not have a predecessor, the "predecessor" is given as the same vertex. This is always the case for the root vertex (the vertex where the search starts), and can happen for vertices that are not scanned at all (in non-connected graphs). The predecessor lists produced from a connected graph is compatible with TreeGraph (see below).

You can reconstruct the tree using TreeGraph:

g = GridGraph[{3, 5}, VertexSize -> {5 -> Medium}]

ps = BreadthFirstScan[g, 5]
(* {2, 5, 2, 5, 5, 5, 4, 5, 6, 7, 8, 9, 10, 11, 12} *)

HighlightGraph[g, TreeGraph[VertexList[g], ps], 
 GraphHighlightStyle -> "Thick"]

enter image description here

added 236 characters in body
Source Link
Szabolcs
  • 236.5k
  • 31
  • 641
  • 1.3k

This list is just the return value of BreadthFirstScan. It has absolutely nothing to do with Sow and Reap.

According to the documentation, it is the list of the predecessors of the BFS tree.

The first element of the list is 2. This means that 2 -> 1 belongs to the tree, where 1 is the first vertex. The second is 5, so 5 -> 2 also belong to the tree (where 2 is the second vertex). And so on. The one tricky thing about this representation is that the "predecessor" of the root vertex is given as the root vertex itself—this is compatible with how TreeGraph works.

You can reconstruct the tree using TreeGraph:

g = GridGraph[{3, 5}, VertexSize -> {5 -> Medium}]

ps = BreadthFirstScan[g, 5]
(* {2, 5, 2, 5, 5, 5, 4, 5, 6, 7, 8, 9, 10, 11, 12} *)

HighlightGraph[g, TreeGraph[VertexList[g], ps], 
 GraphHighlightStyle -> "Thick"]

enter image description here

This list is just the return value of BreadthFirstScan. It has absolutely nothing to do with Sow and Reap.

According to the documentation, it is the list of the predecessors of the BFS tree.

The first element of the list is 2. This means that 2 -> 1 belongs to the tree, where 1 is the first vertex. The second is 5, so 5 -> 2 also belong to the tree (where 2 is the second vertex). And so on.

You can reconstruct the tree using TreeGraph:

g = GridGraph[{3, 5}, VertexSize -> {5 -> Medium}]

ps = BreadthFirstScan[g, 5]
(* {2, 5, 2, 5, 5, 5, 4, 5, 6, 7, 8, 9, 10, 11, 12} *)

HighlightGraph[g, TreeGraph[VertexList[g], ps], 
 GraphHighlightStyle -> "Thick"]

enter image description here

This list is just the return value of BreadthFirstScan. It has absolutely nothing to do with Sow and Reap.

According to the documentation, it is the list of the predecessors of the BFS tree.

The first element of the list is 2. This means that 2 -> 1 belongs to the tree, where 1 is the first vertex. The second is 5, so 5 -> 2 also belong to the tree (where 2 is the second vertex). And so on. The one tricky thing about this representation is that the "predecessor" of the root vertex is given as the root vertex itself—this is compatible with how TreeGraph works.

You can reconstruct the tree using TreeGraph:

g = GridGraph[{3, 5}, VertexSize -> {5 -> Medium}]

ps = BreadthFirstScan[g, 5]
(* {2, 5, 2, 5, 5, 5, 4, 5, 6, 7, 8, 9, 10, 11, 12} *)

HighlightGraph[g, TreeGraph[VertexList[g], ps], 
 GraphHighlightStyle -> "Thick"]

enter image description here

Source Link
Szabolcs
  • 236.5k
  • 31
  • 641
  • 1.3k

This list is just the return value of BreadthFirstScan. It has absolutely nothing to do with Sow and Reap.

According to the documentation, it is the list of the predecessors of the BFS tree.

The first element of the list is 2. This means that 2 -> 1 belongs to the tree, where 1 is the first vertex. The second is 5, so 5 -> 2 also belong to the tree (where 2 is the second vertex). And so on.

You can reconstruct the tree using TreeGraph:

g = GridGraph[{3, 5}, VertexSize -> {5 -> Medium}]

ps = BreadthFirstScan[g, 5]
(* {2, 5, 2, 5, 5, 5, 4, 5, 6, 7, 8, 9, 10, 11, 12} *)

HighlightGraph[g, TreeGraph[VertexList[g], ps], 
 GraphHighlightStyle -> "Thick"]

enter image description here