1
$\begingroup$

Consider this tree:

Simple binary tree

If I traverse it using post-order, I'd start at B (as it is the leftmost leaf) and that's where my misunderstanding begins. I know B is the first and A will be the last node in post order, as the rule is left-right-root. One of my university professors said the correct answer for the post-order traversal of a tree similar to the one above would be B, C, D, E, A, but in my understanding, it should be B, D, E, C, A.

Am I getting it wrong? Shouldn't I evaluate (C,D),(C,E) as a subtree and then go back to the parent tree?

$\endgroup$
0
$\begingroup$

You are right. You finish each sub-tree before printing that sub-tree's root node. The correct order is B, D, E, C, A

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.