0

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

Eric Lippert
  • 647,829
  • 179
  • 1,238
  • 2,067
  • 1
    Useful info: When to use Preorder, Postorder, and Inorder Binary Search Tree Traversal strategies http://stackoverflow.com/questions/9456937/when-to-use-preorder-postorder-and-inorder-binary-search-tree-traversal-strate – Doro Apr 10 '14 at 15:54

2 Answers2

1

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.

nick w.
  • 139
  • 3
  • 4
0

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.

RichieHindle
  • 272,464
  • 47
  • 358
  • 399