AI InterviewSearch…Search problems, topics, or pages…Ctrl KGet started
Easybsttraversal

~45s

The sorted traversal

Which traversal of a binary search tree visits the keys in ascending sorted order?

Show the answer and the worked solution

Correct answer: A.

Inorder

Worked solution

  1. Inorder visits the left subtree, then the node, then the right subtree.
  2. In a BST every key on the left is smaller than the node and every key on the right is larger.
  3. Applying that at every node makes the visit sequence sorted from smallest to largest.

Answer: Inorder.

The idea

Inorder traversal of a BST is the cheapest sorted listing you can get from one, which is why an inorder walk is the standard test that a tree really is a BST.

Shortcut. In a BST left < node < right, so visiting left, node, right yields increasing keys, and that is exactly inorder.

Common trap. "Preorder" tempts as the traversal usually listed first and the one that rebuilds a BST, but it starts at the root, which is rarely the smallest key.

The sorted traversal — Aptitude Question

The sorted traversal: Which traversal of a binary search tree visits the keys in ascending sorted order? Answer and worked solution on CodeKairo.

Question

Which traversal of a binary search tree visits the keys in ascending sorted order?

Options

  1. Inorder
  2. Level-order
  3. Postorder
  4. Preorder
Show the answer and the worked solution

Correct answer: A. Inorder

Worked solution

  1. Inorder visits the left subtree, then the node, then the right subtree.
  2. In a BST every key on the left is smaller than the node and every key on the right is larger.
  3. Applying that at every node makes the visit sequence sorted from smallest to largest.

Answer: Inorder.

The idea

Inorder traversal of a BST is the cheapest sorted listing you can get from one, which is why an inorder walk is the standard test that a tree really is a BST.

Shortcut. In a BST left < node < right, so visiting left, node, right yields increasing keys, and that is exactly inorder.

Common trap. "Preorder" tempts as the traversal usually listed first and the one that rebuilds a BST, but it starts at the root, which is rarely the smallest key.

All Data Structures & Algorithms questions · placement mock tests