What is the order of nodes visited in an inorder tree traversal?
Inorder traversal visits nodes in the order: Left subtree, then Root node, then Right subtree.
Click to reveal answer
beginner
Why is inorder traversal useful for binary search trees (BST)?
Inorder traversal of a BST visits nodes in sorted ascending order because it visits left (smaller), root, then right (larger) nodes.
Click to reveal answer
beginner
Show the recursive steps for inorder traversal on a node.
1. Traverse the left subtree recursively. 2. Visit the root node. 3. Traverse the right subtree recursively.
Click to reveal answer
beginner
What is the output of inorder traversal on this tree? Root: 2 Left child: 1 Right child: 3
The inorder traversal visits nodes in order: 1 -> 2 -> 3
Click to reveal answer
beginner
What is the time complexity of inorder traversal on a binary tree with n nodes?
The time complexity is O(n) because each node is visited exactly once.
Click to reveal answer
In inorder traversal, which node is visited first?
ALeft child
BRoot node
CRight child
DNone
✗ Incorrect
In inorder traversal, the left subtree is visited first before the root.
What is the inorder traversal output of a BST with nodes 2, 1, 3?
A2 -> 1 -> 3
B1 -> 2 -> 3
C3 -> 2 -> 1
D1 -> 3 -> 2
✗ Incorrect
Inorder traversal visits nodes in ascending order for BST: left, root, right.
Which traversal order is Left, Root, Right?
APreorder
BPostorder
CInorder
DLevel order
✗ Incorrect
Inorder traversal visits left subtree, then root, then right subtree.
How many times is each node visited in inorder traversal?
AOnce
BTwice
CThree times
DDepends on tree height
✗ Incorrect
Each node is visited exactly once during inorder traversal.
What is the time complexity of inorder traversal on a tree with n nodes?
AO(1)
BO(log n)
CO(n log n)
DO(n)
✗ Incorrect
Inorder traversal visits all n nodes once, so time complexity is O(n).
Explain how inorder traversal works on a binary tree.
Think about the order of visiting nodes: left, root, right.
You got /4 concepts.
Describe why inorder traversal outputs sorted values for a binary search tree.
Consider how BST nodes are arranged and how inorder visits them.
You got /5 concepts.
Practice
(1/5)
1. What is the order of nodes visited in an inorder traversal of a binary tree?
easy
A. Root, Left subtree, Right subtree
B. Root, Right subtree, Left subtree
C. Right subtree, Root, Left subtree
D. Left subtree, Root, Right subtree
Solution
Step 1: Understand inorder traversal definition
Inorder traversal visits nodes in the order: left subtree first, then root node, then right subtree.
Step 2: Apply the order to the tree nodes
This means we first explore all nodes in the left subtree, then the root, then the right subtree.
Final Answer:
Left subtree, Root, Right subtree -> Option D
Quick Check:
Inorder = Left, Root, Right [OK]
Hint: Remember: Inorder means Left, Root, then Right [OK]
Common Mistakes:
Confusing inorder with preorder or postorder
Visiting root before left subtree
Visiting right subtree before root
2. Which of the following Python function definitions correctly implements inorder traversal of a binary tree node root?
easy
A. def inorder(root):
if root:
inorder(root.left)
print(root.val)
inorder(root.right)
B. def inorder(root):
if root:
print(root.val)
inorder(root.left)
inorder(root.right)
C. def inorder(root):
if root:
inorder(root.right)
print(root.val)
inorder(root.left)
D. def inorder(root):
if root:
inorder(root.right)
inorder(root.left)
print(root.val)
Solution
Step 1: Recall inorder traversal order
Inorder visits left subtree, then root, then right subtree.
Step 2: Match code to order
def inorder(root):
if root:
inorder(root.left)
print(root.val)
inorder(root.right) calls inorder on left, prints root value, then calls inorder on right, matching inorder traversal.
Final Answer:
Option A code correctly implements inorder traversal -> Option A
Quick Check:
Left, Root, Right order in code [OK]
Hint: Inorder: recursive left call, print root, recursive right call [OK]
Common Mistakes:
Printing root before left subtree call
Swapping left and right subtree calls
Missing base case check for None
3. Given the binary tree below, what is the output of inorder traversal?
C. The base case is missing; should check if root is None first
D. The function calls right subtree before printing root
Solution
Step 1: Analyze base case in inorder function
The function checks root.left and root.right but never checks if root itself is None, which causes errors or no output if root is None.
Step 2: Identify missing base case effect
Without checking if root is None, the function may fail or skip printing when called with None, so adding if root is None: return fixes it.
Final Answer:
The base case is missing; should check if root is None first -> Option C
Quick Check:
Check root None before recursion [OK]
Hint: Always check if node is None before recursion [OK]
Common Mistakes:
Not checking if root is None before accessing attributes
Incorrect order of print and recursive calls
Forgetting to create root node before traversal
5. You have a binary tree where some nodes have only one child. Which inorder traversal output correctly represents the tree below?
5
/ \
3 8
\ \
4 9
Options:
A) 3 5 4 8 9
B) 4 3 5 9 8
C) 3 4 5 8 9
D) 5 3 4 8 9
hard
A. 3 5 4 8 9
B. 3 4 5 8 9
C. 4 3 5 9 8
D. 5 3 4 8 9
Solution
Step 1: Perform inorder traversal on given tree
Start at root (5), visit left subtree: node 3 has no left child, so print 3, then visit right child 4, print 4. Then print root 5. Then visit right subtree: node 8 has no left child, print 8, then right child 9, print 9.
Step 2: Write the output sequence
The output is: 3 4 5 8 9.
Final Answer:
3 4 5 8 9 -> Option B
Quick Check:
Inorder visits left, root, right even if child missing [OK]
Hint: Inorder visits left subtree fully before root, even if missing nodes [OK]
Common Mistakes:
Skipping nodes with only one child
Printing root before left subtree
Confusing preorder or postorder output
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.