Which traversal of a binary search tree visits the keys in sorted order, and how does that traversal work?

technical-conceptual · Junior level · software-engineering

What the interviewer is really asking

Tests whether the candidate knows the in-order traversal, why it yields sorted output on a BST, and can distinguish it from pre-order and post-order.

What to say

What to avoid

Example answers

Strong: In-order traversal gives sorted output: you recurse into the left subtree, visit the current node, then recurse into the right subtree. It works because of the BST invariant — at every node the left subtree is all smaller and the right is all larger, so left-node-right at each step strings the keys together in ascending order. It's O(n) since you touch each node once.

Weak: I think it's pre-order — you visit the root first so you get them in order.

Want questions matched to your role? Paste a job title, job description, or CV and get a personalized set, or go Pro to unlock the full bank.