0
0
DSA Javascriptprogramming~10 mins

BST Property and Why It Matters in DSA Javascript - Interactive Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
A>
B<
C==
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>' instead of '<' causes wrong subtree choice.
Using '==' or '!=' is incorrect for BST placement.
2fill in blank
medium

Complete 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'
A>
B<=
C==
D<
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.
3fill in blank
hard

Fix 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'
A>
B<
C<=
D>=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' causes searching the wrong subtree.
Using '<=' or '>=' can cause incorrect search paths.
4fill in blank
hard

Fill 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'
A>=
B<
C<=
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' for left child check causes wrong validation.
Using '>=' for right child check causes wrong validation.
5fill in blank
hard

Fill 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'
Aleft
Bvalue
Cright
Dparent
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'parent' instead of 'left' or 'right' causes errors.
Pushing node instead of node.value adds wrong data.