Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why pre-order traversal is favored for cloning a tree?

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?

like image 574
Geek Avatar asked Jan 15 '23 13:01

Geek


1 Answers

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.

like image 148
Yarneo Avatar answered Jan 22 '23 11:01

Yarneo