Repaso
EspaƱol
Algorithms & DSIntermediateALG-21

Which traversal of a binary search tree yields keys in sorted order?

Options

  1. Pre-order
  2. In-order (Correct option)
  3. Post-order
  4. Level-order

Answer

In-order

Why

In a BST, every key in a node's left subtree is smaller and every key in its right subtree is bigger.

In-order traversal visits left subtree, then the node, then right subtree, so it naturally outputs keys from smallest to largest.

Pre-order (node first) is used to copy trees; post-order (node last) to delete them.

Remember

BST + in-order = sorted output.

Key terms

Practice this question in Repaso