6. Explain in-order, pre-order and post-order traversal of a binary tree.
MediumData structures & algorithms
Technical
Show model answer
Pre-order visits the node, then the left and right subtrees (useful to copy or serialise a tree). In-order visits left, node, right; on a binary search tree it produces sorted order. Post-order visits left, right, then the node (useful to delete a tree or evaluate expressions).
Level-order is a fourth traversal that uses a queue to visit one depth at a time.