I understand the idea behind the tree traversal as well as implementations, but here is the question. Why do we need them all?
Right now I only know that preorder traversal is used when parsing math expressions. From the Wikipedia I also read than:
- Inorder traversal is particularly common to use an inorder traversal on a binary search tree because this will return values from the underlying set in order, according to the comparator that set up the binary search tree (hence the name). Preorder traversal
- Traversing a tree in preorder while inserting the values into a new tree is common way of making a complete copy of a binary search tree. One can also use preorder traversals to get a prefix expression (Polish notation) from expression trees: traverse the expression tree preorderly. (which I already stated)
But these examples are rather vague. Can anyone describe this in more depth. Especially with examples.