What does BST stand for and what is its key property?
BST stands for Binary Search Tree. Its key property is that for every node, all values in the left subtree are smaller, and all values in the right subtree are larger.
Click to reveal answer
beginner
What is the main idea to check if a binary tree is a BST?
To check if a binary tree is a BST, verify that each node's value is within a valid range defined by its ancestors, ensuring left children are smaller and right children are larger.
Click to reveal answer
intermediate
Why can't we just check if left child < node and right child > node to validate BST?
Because the BST property must hold for all descendants, not just immediate children. A node in the left subtree must be less than the current node, even if it's deeper down.
Click to reveal answer
intermediate
What is the role of min and max values in BST validation?
Min and max values track the allowed range for node values during recursion. Each node must be greater than min and less than max to satisfy BST rules.
Click to reveal answer
beginner
What is the time complexity of validating a BST?
The time complexity is O(n), where n is the number of nodes, because each node is visited once during the validation.
Click to reveal answer
What must be true for every node in a BST?
ANo children nodes
BLeft subtree nodes are larger, right subtree nodes are smaller
CAll nodes have equal values
DLeft subtree nodes are smaller, right subtree nodes are larger
✗ Incorrect
In a BST, all nodes in the left subtree are smaller and all nodes in the right subtree are larger than the current node.
Which method helps validate a BST correctly?
ACheck only immediate children values
BUse min and max range limits during recursion
CCount nodes in left and right subtree
DCheck if tree is balanced
✗ Incorrect
Using min and max range limits ensures all descendants satisfy BST properties, not just immediate children.
What is the time complexity to validate a BST?
AO(n)
BO(log n)
CO(1)
DO(n^2)
✗ Incorrect
Each node is visited once, so the time complexity is O(n).
If a node violates the BST property, what should the validation function return?
ATrue
BNull
CFalse
DContinue checking
✗ Incorrect
If any node violates the BST property, the function should return False immediately.
What is the initial min and max value when starting BST validation?
AMin = INT_MIN, Max = INT_MAX
BMin = 0, Max = 0
CMin = node value, Max = node value
DNo min and max needed
✗ Incorrect
We start with the full integer range to allow any value for the root node.
Explain how to validate if a binary tree is a BST using recursion and range limits.
Think about how each node's value must fit between limits passed down from its ancestors.
You got /4 concepts.
Describe why checking only immediate children is not enough to validate a BST.
Consider a node deep in the left subtree that might be greater than the root.
You got /4 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 nodes in the left subtree are smaller and all nodes in the right subtree are larger
C. All nodes have unique values
D. The tree is perfectly balanced
Solution
Step 1: Understand BST property
A BST requires that for every node, values in the left subtree are smaller and values in the right subtree are larger.
Step 2: Compare options with BST definition
For each node, all nodes in the left subtree are smaller and all nodes in the right subtree are larger matches the BST property exactly, while others describe different tree properties.
Final Answer:
For each node, all nodes in the left subtree are smaller and all nodes in the right subtree are larger -> Option B
Quick Check:
BST property = For each node, all nodes in the left subtree are smaller and all nodes in the right subtree are larger [OK]
Hint: Remember BST means left < node < right for all nodes [OK]
Common Mistakes:
Confusing BST with balanced tree
Thinking all nodes must have two children
Assuming unique values define BST
2. Which of the following C function signatures is correct to check if a binary tree is a BST?
easy
A. int isBST(struct Node* root, int min, int max);
B. void isBST(struct Node* root);
C. int isBST(struct Node* root);
D. bool isBST(struct Node* root, int min, int max);
Solution
Step 1: Identify typical BST check function parameters
Checking BST usually requires passing current node and min/max limits to validate subtree values.
Step 2: Match function signatures
int isBST(struct Node* root, int min, int max); uses int return type and min/max parameters, which is common in C. bool isBST(struct Node* root, int min, int max); uses bool which is not standard C. Options B and C lack min/max parameters.
Final Answer:
int isBST(struct Node* root, int min, int max); -> Option A
Quick Check:
BST check needs min/max limits and int return [OK]
Hint: Use min/max limits in function parameters for BST check [OK]
Common Mistakes:
Omitting min/max parameters
Using bool type in plain C
Using void return type for boolean check
3. Given the following tree structure and code snippet, what will be the output?
The node with value 6 is in the right subtree of 10 but less than 10, violating BST property.
Step 2: Trace isBSTUtil calls
When checking node 6, min=15 and max=INT_MAX, 6 <= 15 fails the condition, so returns 0.
Final Answer:
0 -> Option D
Quick Check:
Node 6 violates BST rules, so output = 0 [OK]
Hint: Check if any node violates min/max limits during recursion [OK]
Common Mistakes:
Ignoring subtree min/max constraints
Assuming all left < root and right > root only locally
Not tracing recursive calls carefully
4. Identify the bug in this BST validation function and select the fix:
int isBST(struct Node* root) {
if (root == NULL) return 1;
if (root->left != NULL && root->left->data >= root->data) return 0;
if (root->right != NULL && root->right->data <= root->data) return 0;
if (!isBST(root->left) || !isBST(root->right)) return 0;
return 1;
}
medium
A. Add min and max parameters to check entire subtree ranges
B. Change >= to > and <= to < in comparisons
C. Remove recursive calls to isBST
D. Return 0 if root is NULL
Solution
Step 1: Understand current checks
The function only compares immediate children with root, missing deeper subtree violations.
Step 2: Explain why min/max parameters are needed
To validate BST fully, we must ensure all nodes in left subtree < root and right subtree > root using min/max limits recursively.
Final Answer:
Add min and max parameters to check entire subtree ranges -> Option A
Quick Check:
Min/max limits fix subtree validation [OK]
Hint: Use min/max limits to validate entire subtree, not just immediate children [OK]
Common Mistakes:
Checking only immediate children
Ignoring subtree value ranges
Misusing comparison operators
5. You want to validate if a binary tree is a BST but the tree may contain duplicate values allowed only on the right subtree. How would you modify the BST validation logic in C?
hard
A. Use strict > and < comparisons for both subtrees
B. Allow duplicates only on left subtree by changing conditions
C. Change the condition to allow node->data >= min and < max for right subtree
D. Ignore duplicates and check only structure
Solution
Step 1: Understand duplicate allowance rule
Duplicates allowed only on right subtree means left subtree nodes must be strictly less, right subtree nodes can be equal or greater.
Step 2: Modify min/max checks accordingly
For left subtree, use node->data > min and < root->data; for right subtree, allow node->data >= root->data and < max.
Final Answer:
Change the condition to allow node->data >= min and < max for right subtree -> Option C
Quick Check:
Allow duplicates on right by using >= on right subtree [OK]
Hint: Allow duplicates on right by using >= comparison there [OK]
Common Mistakes:
Allowing duplicates on left subtree incorrectly
Using strict inequalities everywhere
Ignoring duplicate rules
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.