Closed leshabirukov closed 9 months ago
Thanks for your remarks.
The order of the visit of siblings does not belong to the guarantees of a DFS algorithms. Not according to the documentation of NoGraphs. And not according to the specification of a DFS as such, e.g., in Wikepedia.
In fact, the recursive DFS shown in Wikipedia visits them "in order", and the non-recursive version visits them in "reversed order" (like the non-recursive implementation in NoGraphs). This is even described in Wikepedia: "These two variations of DFS visit the neighbors of each vertex in the opposite order from each other: the first neighbor of v visited by the recursive variation is the first one in the list of adjacent edges, while in the iterative variation the first visited neighbor is the last one in the list of adjacent edges."
And in fact, many other non-recursive implementations of the DFS behave like this.
In this situation, changing the implementation would not "fix" something, but would make its behavior strange and unexpected. Thus, I would also not confirm the word "compatibility" - because a change would make the behavior incompatible to typical implementations.
But I am with you that the documentation should be improved: It should state that the order of the sibling visits is not specified, and might even change in the future. Like this, surprises for users could be prevented.
Oh, thank you for explanation, I didn't know this. Thing I still disagree, even with Wikipedia, is they call it 'implementation', if it changes the order, it is rather 'variation'.
Also, though mathematically neighbours order in graph is not determined, practically it frequently is.
While doing depth first search(DFS), siblings (children of one parent) are visited in order, reversed, comparing to order
next_thing
reported them.Being aware of
nog
internals, I doubt this can be fixed painlessly, but this must be documented explicitly and loud, avoiding surprising user that way.Sometime, may be, we to introduce a compatibility mode, for ones who needs
canonical
traversal, I suggest doing it only if someone else hit this issue.