Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to check if a value should go to the left subtree in a BST.
DSA Javascript
if (value [1] node.value) { // go left }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>' instead of '<' causes wrong subtree choice.
Using '==' or '!=' is incorrect for BST placement.
✗ Incorrect
In a BST, values less than the current node go to the left subtree.
2fill in blank
mediumComplete the code to insert a new value into the BST correctly.
DSA Javascript
if (value [1] node.value) { node.left = insert(node.left, value); } else { node.right = insert(node.right, value); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<=' causes duplicates to go left, which may be incorrect depending on BST rules.
Using '==' is not suitable for comparison here.
✗ Incorrect
Values less than the node go to the left subtree; others go right.
3fill in blank
hardFix the error in the BST search condition to find a value.
DSA Javascript
if (node.value [1] value) { return search(node.left, value); } else if (node.value === value) { return node; } else { return search(node.right, value); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' causes searching the wrong subtree.
Using '<=' or '>=' can cause incorrect search paths.
✗ Incorrect
If the node's value is greater than the target, search left subtree; else right.
4fill in blank
hardFill both blanks to create a BST property check function.
DSA Javascript
function isBST(node) {
if (!node) return true;
if (node.left && node.left.value [1] node.value) return false;
if (node.right && node.right.value [2] node.value) return false;
return isBST(node.left) && isBST(node.right);
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' for left child check causes wrong validation.
Using '>=' for right child check causes wrong validation.
✗ Incorrect
Left child must be less than node (so fail if left >= node). Right child must be greater than node (fail if right <= node).
5fill in blank
hardFill all three blanks to create a function that collects BST values in order.
DSA Javascript
function inorderTraversal(node, result = []) {
if (!node) return result;
inorderTraversal(node.[1], result);
result.push(node.[2]);
inorderTraversal(node.[3], result);
return result;
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'parent' instead of 'left' or 'right' causes errors.
Pushing node instead of node.value adds wrong data.
✗ Incorrect
Inorder traversal visits left subtree, then node value, then right subtree.