You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
the current implementation of walk_tree_bfs actually implements DFS, as evidenced by the fact that it is almost identical to walk_tree_dfs
in other words, walk_tree_bfs node {...} is identical to walk_tree_dfs node { |node,level| node.children.each { |child| ... }}, modulo some corner-cases
I think the tests used in test/acts_as_tree_test.rb are not deep enough to show the difference, but if you take
1
-2
--3
---4
-5
--6
---7
then the current implementation generate
1 2 5 3 4 6 7
while I believe true BFS would generate
1 2 5 3 6 4 7
(4 and 6 are switched)
a correct implementation should use a FIFO to keep tracks of the next generation; I will suggest one later, unless someone beats me to it or explains that I'm mistaken
The text was updated successfully, but these errors were encountered:
the current implementation of
walk_tree_bfs
actually implements DFS, as evidenced by the fact that it is almost identical towalk_tree_dfs
in other words,
walk_tree_bfs node {...}
is identical towalk_tree_dfs node { |node,level| node.children.each { |child| ... }}
, modulo some corner-casesI think the tests used in
test/acts_as_tree_test.rb
are not deep enough to show the difference, but if you takethen the current implementation generate
while I believe true BFS would generate
(
4
and6
are switched)a correct implementation should use a FIFO to keep tracks of the next generation; I will suggest one later, unless someone beats me to it or explains that I'm mistaken
The text was updated successfully, but these errors were encountered: