Given the following 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?


migrated from cstheory.stackexchange.com May 18 '12 at 18:20

This question came from our site for theoretical computer scientists and researchers in related fields.

  • 3
    $\begingroup$ Which book are you referencing? "The book" does not make sense without context. $\endgroup$ – Dave Clarke May 18 '12 at 18:50
  • $\begingroup$ In fact is a study guide and this is a question that's why there is no context $\endgroup$ – Jorge Zapata May 18 '12 at 18:51
  • $\begingroup$ This is random traversal :) what is the usage? $\endgroup$ – user742 May 18 '12 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 May 18 '12 at 21:16

You are not wrong.

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

  • $\begingroup$ perfect I just wanted to be sure, thanks $\endgroup$ – Jorge Zapata May 18 '12 at 18:54
  • 2
    $\begingroup$ Unordered children could explain why C comes first, but not the position of B. $\endgroup$ – Raphael May 18 '12 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$ – Josh Lockhart May 19 '12 at 13:09

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.