graph icon indicating copy to clipboard operation
graph copied to clipboard

feat(#124): full traverse

Open williamfzc opened this issue 1 year ago • 3 comments

Hi :)

This is an implementation (draft) for #124 .

  • add TopologicalEntries for searching entries
  • add FullTraverse for walking all the nodes

It already matches my need. However, as a library, there are still some issues that need to be discussed:

  • It does not include the semantics of BFS or DFS
  • it may visits some nodes multiple times

williamfzc avatar May 16 '23 15:05 williamfzc

Hi! Thanks for the PR. I do have one question in mind: What is the advantage of/difference between FullTraverse and a regular loop over the predecessors? Like this:

predecessorMap, _ := g.PredecessorMap()

for vertex, _ := range predecessorMap {
    _ = BFS(g, vertex, visit)
}

dominikbraun avatar May 18 '23 19:05 dominikbraun

Hi! Thanks for the PR. I do have one question in mind: What is the advantage of/difference between FullTraverse and a regular loop over the predecessors? Like this:

predecessorMap, _ := g.PredecessorMap()

for vertex, _ := range predecessorMap {
    _ = BFS(g, vertex, visit)
}

This loop seems it will initiate BFS on all vertices in the graph. But the FullTraverse will only initiate BFS on the entry vertices.

I am not pretty sure that which one is better/expected.

williamfzc avatar May 19 '23 14:05 williamfzc

Hi! Thanks for the PR. I do have one question in mind: What is the advantage of/difference between FullTraverse and a regular loop over the predecessors? Like this:

predecessorMap, _ := g.PredecessorMap()

for vertex, _ := range predecessorMap {
    _ = BFS(g, vertex, visit)
}

This loop seems it will initiate BFS on all vertices in the graph. But the FullTraverse will only initiate BFS on the entry vertices.

I am not pretty sure that which one is better/expected.

I would argue that FullTraverse is the better solution, since it guarantees each vertex is only visited up to one time O(V). Whereas the sample code above will guarantee O(V^2) for a complete graph. That said however based on how it is currently written it appears FullTraverse will not visit every vertex if the graph has cycles. By that definition I wouldn't consider it a FullTraverse.

If the intention is to simply visit every vertex, then adding a Vertices function to the graph would likely be a better solution or a Visit function at the that took a visit function as a parameter and handled the traversal automatically, preferably without making a clone of the Vertices which is likely what a Vertices function would force the user to use.

jonbrandenburg avatar Jul 14 '23 05:07 jonbrandenburg