4

I know the definition of pre-order traversal and want to understand why pre-order traversal strategy is favored for cloning a tree ? I mean why it is preferred more than the other traversal mechanisms like in order traversal and post order traversals?

Geek
  • 26,489
  • 43
  • 149
  • 227
  • As a guess, because it's probably the easiest way to copy. An inorder traversal may require going up and down the tree too much, and a post order traversal is also not quite so efficient. So pre-order seems the most logical. – Tony The Lion Sep 17 '12 at 09:38

1 Answers1

9

In order to build the children, you must have the parent (root) built also. Pre-order is the only order that doesn't traverse through a child before passing its parent, unlike in-order and post-order which do.

Yarneo
  • 2,922
  • 22
  • 30