youtube_tutorials icon indicating copy to clipboard operation
youtube_tutorials copied to clipboard

Wrong output

Open FredericoIsaac opened this issue 3 years ago • 3 comments

print(tree.print_tree("postorder"))

4-5-2-6-7-3-1-

not:

4-2-5-6-3-7-1

FredericoIsaac avatar Aug 19 '20 05:08 FredericoIsaac

Can you please refer to the offending file for which your comment is directed to?

vprusso avatar Aug 19 '20 12:08 vprusso

Yes of course. Btw thanks for your work! data_structures/trees/binary_trees/binary_tree_recursive_dfs_traversals.py def postorder_print(self, start, traversal): """Left->Right->Root""" if start: traversal = self.postorder_print(start.left, traversal) traversal = self.postorder_print(start.right, traversal) traversal += (str(start.value) + "-") return traversal

1-2-4-5-3-6-7-

4-2-5-1-6-3-7

# 4-2-5-6-3-7-1

1

/ \

2 3

/ \ / \

4 5 6 7

FredericoIsaac avatar Aug 19 '20 17:08 FredericoIsaac

I'm not sure I see the issue. The post-order recursively goes to the left, right, and then prints. This is the correct process for post-order traversal.

vprusso avatar Aug 19 '20 19:08 vprusso