Question

how do I choose how should i traverse a tree in-order, pre-order, post-order?

I understand what is the difference between those, but what is the practical difference? Time complexity?

thank you..

Was it helpful?

Solution

The type of traversal you should use really depends on what it is you are trying to do.

For example;

Postorder would be used when deleting a tree, as a node can only be deleted after is left and right subtrees have both been deleted.

PreOrder would be used when you want to copy a tree, as the parent node needs to be created before you can create subtrees for that particular node.

Hopefully this will help you : http://www.geeksforgeeks.org/618/

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