Question

I have knew that in-order is the meaning of ascending-order,and

post-order is used to delete the whole tree,

but when to use pre-order?Or what is the advantage of pre-order?

Just tell me simplely is enough

Was it helpful?

Solution 2

Pre-order is good for searching - if the thing you're searching for is in the current node, you save the bother of searching its children.

OTHER TIPS

Pre-order traversal explores the roots before exploring leaves. You use pre-order because you want to process the roots before you process the leaves. Some applications for pre-order

  1. Create a binary search tree with minimal height from a sorted array.
  2. Clone a binary tree.
  3. Create a linked list for nodes on the same depth on a binary tree.

As you can see, application #1 and #2 rely on the creation of the parent node before you create child nodes. #3 allows you to create a linked list per depth before collecting nodes at the same depth.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top