4
$\begingroup$

Given the following tree:

tree

Which traversal method would give as result the following output: CDBEA?

The answer in my study guide is Postorder, but I think postorder would output: DEBCA. Am I wrong?

$\endgroup$
4
  • 3
    $\begingroup$ Which book are you referencing? "The book" does not make sense without context. $\endgroup$ Commented May 18, 2012 at 18:50
  • $\begingroup$ In fact is a study guide and this is a question that's why there is no context $\endgroup$ Commented May 18, 2012 at 18:51
  • $\begingroup$ This is random traversal :) what is the usage? $\endgroup$
    – user742
    Commented May 18, 2012 at 18:52
  • 2
    $\begingroup$ The question is fine (though it might be better to generalize it a little bit so it is more useful for others also), it is a normal question a CS student might ask. $\endgroup$
    – Kaveh
    Commented May 18, 2012 at 21:16

1 Answer 1

4
$\begingroup$

You are not wrong.

A postorder traversal visits the left subtree, then the right subtree, then the root of the current tree (recursively).

$\endgroup$
3
  • $\begingroup$ perfect I just wanted to be sure, thanks $\endgroup$ Commented May 18, 2012 at 18:54
  • 2
    $\begingroup$ Unordered children could explain why C comes first, but not the position of B. $\endgroup$
    – Raphael
    Commented May 18, 2012 at 20:27
  • $\begingroup$ I can't make sense of the traversal CDBEA. Is this just random? If not, what sort of traversal is being used? $\endgroup$ Commented May 19, 2012 at 13:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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