Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to check if a node's left child value is less than the node's value.
DSA C
if (node->left != NULL && node->left->value [1] node->value) { // left child is less }
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>' instead of '<' for left child comparison.
Using '==' which only checks equality, not order.
✗ Incorrect
In a BST, the left child's value must be less than the node's value, so '<' is correct.
2fill in blank
mediumComplete the code to check if a node's right child value is greater than the node's value.
DSA C
if (node->right != NULL && node->right->value [1] node->value) { // right child is greater }
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' for right child comparison.
Using '==' which only checks equality, not order.
✗ Incorrect
In a BST, the right child's value must be greater than the node's value, so '>' is correct.
3fill in blank
hardFix the error in the code that checks BST property for the left child.
DSA C
if (node->left != NULL && node->left->value [1] node->value) { // correct BST property }
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>=' which allows equal or greater values on left child.
Using '<=' which allows equal values, violating strict BST property.
✗ Incorrect
The left child's value must be strictly less than the node's value, so '<' is correct.
4fill in blank
hardFill both blanks to complete the BST validation condition for a node.
DSA C
if ((node->left == NULL || node->left->value [1] node->value) && (node->right == NULL || node->right->value [2] node->value)) { // node satisfies BST property }
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<=' or '>=' which allow equal values, violating strict BST rules.
Swapping operators between left and right child checks.
✗ Incorrect
Left child must be less than node ('<'), right child must be greater than node ('>').
5fill in blank
hardFill all three blanks to complete the recursive BST validation function.
DSA C
int isBST(Node* node) {
if (node == NULL) return 1;
if ((node->left == NULL || node->left->value [1] node->value) &&
(node->right == NULL || node->right->value [2] node->value) &&
isBST(node->left) && isBST(node->right)) {
return [3];
}
return 0;
}Attempts:
3 left
💡 Hint
Common Mistakes
Returning 0 instead of 1 when BST property holds.
Using wrong comparison operators for left or right child.
✗ Incorrect
Left child must be less than node ('<'), right child greater ('>'), and return 1 for true.
