Binary Tree Traversal code has two mistakes:
-
In
breadthFirstTraversal
, the lineobserved.enqueue(root)
should bediscovered.enqueue(root)
-
In
depthFirstTraversal
, if you are using theStack
implementation from the book as opposed to including the one from kirupa.com, you will be missing thelength
method.
Both of these issues are fixed in the version of the full example shared here: kirupa/data_structures_algorithms/binary_tree_traversal.htm at master · kirupa/kirupa · GitHub
Thanks again to @timfrobisher for pointing these two issues out.