-1

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

tania
  • 1,086
  • 2
  • 12
  • 31

1 Answers1

1

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/

Paddyd
  • 1,870
  • 16
  • 26