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
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
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
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.
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.