Domanda

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

È stato utile?

Soluzione

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/

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top