LOGBOOK

HELP

Quiz Entry - updated: 2026.09.29

Do the preorder, postorder and inorder traversals of a binary tree visit the leaves in the same order or in different orders?

Always in the same relative order. All three traversals finish a node's entire left subtree before starting its right subtree; they differ only in when the internal node itself is visited, and leaves have no subtrees whose order could change.

Look at what the three algorithms share:

Left subtree Node Right subtree
Preorder 2nd 1st 3rd
Inorder 1st 2nd 3rd
Postorder 1st 3rd 2nd

In every row, the left subtree comes before the right subtree. Only the position of the node itself moves.

Now take any two leaves. Going up from them, there is a lowest node where their paths split, with one leaf in its left subtree and the other in its right subtree. All three traversals process that left subtree completely before the right one, so all three meet the first leaf before the second. Leaves are never the "node itself" of anything with children, so their relative order is fixed.

Example: in a tree with root A, left child B and right child C, all three traversals list B before C (ABC, BAC, BCA).

From Quiz: ADS / Trees: Structure, Storage and Traversals | Updated: Sep 29, 2026