In a Binary Search Tree (BST), for every node, all values in its left subtree are smaller, and all values in its right subtree are larger than the node's value.
Click to reveal answer
beginner
Why does the BST property matter?
It allows fast searching, insertion, and deletion because we can decide to go left or right at each node, reducing the search space quickly.
Click to reveal answer
intermediate
What happens if the BST property is violated?
The tree no longer guarantees efficient search operations, and it behaves like a regular binary tree, losing the speed advantage.
Click to reveal answer
beginner
How does the BST property help in searching for a value?
At each node, compare the target value with the node's value. If smaller, go left; if larger, go right. This halves the search space each step.
Click to reveal answer
intermediate
Can a BST have duplicate values? How does the property handle them?
Usually, BSTs do not allow duplicates or store duplicates consistently (e.g., all duplicates go to the right). The property must be maintained to keep order.
Click to reveal answer
What does the BST property ensure about the left subtree of a node?
AAll values are smaller than the node's value
BAll values are larger than the node's value
CValues can be any number
DAll values are equal to the node's value
✗ Incorrect
The BST property states that all values in the left subtree must be smaller than the node's value.
Why is the BST property important for search operations?
AIt makes the tree balanced automatically
BIt stores values in random order
CIt allows skipping half of the tree at each step
DIt prevents insertion of new nodes
✗ Incorrect
Because the BST property lets us decide to go left or right, we skip half the nodes each time, making search faster.
If a node's value is 10, which subtree can contain the value 15?
ALeft subtree
BNone
CEither subtree
DRight subtree
✗ Incorrect
Values larger than 10 must be in the right subtree according to the BST property.
What happens if the BST property is broken?
ATree becomes balanced
BSearch becomes slower
CInsertion is faster
DTree becomes empty
✗ Incorrect
Breaking the BST property means we can't efficiently decide which subtree to search, slowing down operations.
How are duplicates usually handled in a BST?
ADuplicates are not allowed or placed consistently (e.g., always right)
BDuplicates go to the left subtree
CDuplicates replace the node
DDuplicates are ignored
✗ Incorrect
BSTs typically disallow duplicates or store them in a consistent subtree to maintain the property.
Explain the BST property and how it helps in searching for a value.
Think about how you decide which way to go when searching.
You got /4 concepts.
Describe what happens if the BST property is violated and why it matters.
Consider the impact on search speed.
You got /3 concepts.
Practice
(1/5)
1. What is the main property that defines a Binary Search Tree (BST)?
easy
A. Each node has exactly two children.
B. For each node, all values in the left subtree are smaller, and all values in the right subtree are larger.
C. All nodes have the same value.
D. Nodes are arranged in a circular linked list.
Solution
Step 1: Understand BST node value rules
In a BST, the left subtree contains values smaller than the node, and the right subtree contains values larger than the node.
Step 2: Compare options with BST definition
For each node, all values in the left subtree are smaller, and all values in the right subtree are larger. matches the BST property exactly, while others describe different structures.
Final Answer:
For each node, all values in the left subtree are smaller, and all values in the right subtree are larger. -> Option B
Quick Check:
BST property = left < node < right [OK]
Hint: Remember: left < node < right defines BST [OK]
Common Mistakes:
Confusing BST with binary tree (not ordered)
Thinking all nodes must have two children
Assuming all values are equal
2. Which of the following is the correct way to check if a value should go to the left subtree in a BST insertion function in JavaScript?
easy
A. if (value < node.value) { insertLeft(); }
B. if (value > node.value) { insertLeft(); }
C. if (value == node.value) { insertLeft(); }
D. if (value >= node.value) { insertLeft(); }
Solution
Step 1: Recall BST insertion rule
Values smaller than the current node go to the left subtree.
Step 2: Match condition to insertion side
Only the condition 'value < node.value' correctly directs insertion to the left.
Final Answer:
if (value < node.value) { insertLeft(); } -> Option A
Quick Check:
Smaller values go left [OK]
Hint: Use < for left subtree insertion [OK]
Common Mistakes:
Using > instead of < for left subtree
Using == which is not for left or right
Using >= which includes equal values incorrectly
3. What will be the in-order traversal output of the following BST?
10
/ \
5 15
/ \ \
3 7 20
medium
A. [20, 15, 10, 7, 5, 3]
B. [10, 5, 3, 7, 15, 20]
C. [3, 5, 7, 10, 15, 20]
D. [5, 3, 7, 10, 15, 20]
Solution
Step 1: Understand in-order traversal
In-order traversal visits left subtree, then node, then right subtree recursively.
Step 2: Apply in-order to given tree
Left subtree of 10: 3, 5, 7; then 10; then right subtree: 15, 20. Combined: [3, 5, 7, 10, 15, 20]
Final Answer:
[3, 5, 7, 10, 15, 20] -> Option C
Quick Check:
In-order = sorted BST values [OK]
Hint: In-order traversal of BST gives sorted values [OK]
Common Mistakes:
Confusing pre-order or post-order with in-order
Listing nodes in insertion order
Reversing the traversal order
4. Consider this BST insertion code snippet in JavaScript:
What is the main issue with this code regarding BST property?
medium
A. It inserts larger values on the left subtree incorrectly.
B. It does not handle the case when node is null.
C. It returns undefined instead of the node.
D. It allows duplicate values on the left subtree, which may break strict BST rules.
Solution
Step 1: Analyze duplicate handling in insertion
The condition 'value <= node.value' inserts duplicates to the left subtree.
Step 2: Understand BST strictness
Strict BSTs require left subtree values strictly less than node value; duplicates on left can break this.
Final Answer:
It allows duplicate values on the left subtree, which may break strict BST rules. -> Option D
Quick Check:
Duplicates on left break strict BST [OK]
Hint: Use < for left to avoid duplicates on left [OK]
Common Mistakes:
Ignoring duplicate value placement
Thinking null check is missing
Confusing left and right subtree insertion
5. You have a BST where some nodes violate the BST property because their left child has a value greater than the node. Which approach best fixes the tree without rebuilding it completely?
hard
A. Swap the values of the violating nodes with their children to restore BST property locally.
B. Ignore the violations as they do not affect search operations.
C. Delete all nodes and insert them again in correct order.
D. Perform an in-order traversal, collect values, then rebuild the BST from sorted values.
Solution
Step 1: Understand the violation type
Left child having greater value than node breaks BST property locally.
Step 2: Choose minimal fix without full rebuild
Swapping values of violating nodes with their children can restore local BST property without full rebuild.
Step 3: Evaluate other options
Perform an in-order traversal, collect values, then rebuild the BST from sorted values. rebuilds fully, Delete all nodes and insert them again in correct order. deletes all nodes (costly), Ignore the violations as they do not affect search operations. ignores problem (wrong).
Final Answer:
Swap the values of the violating nodes with their children to restore BST property locally. -> Option A
Quick Check:
Local swaps fix BST violations efficiently [OK]
Hint: Fix BST by swapping violating node values locally [OK]
Common Mistakes:
Rebuilding entire tree unnecessarily
Ignoring violations thinking no impact
Deleting all nodes instead of fixing
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.