0
0
DSA Javascriptprogramming~10 mins

BST Find Minimum Element 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 start searching for the minimum element from the root node.

DSA Javascript
function findMin(root) {
  let current = [1];
  while (current.left !== null) {
    current = current.left;
  }
  return current.data;
}
Drag options to blanks, or click blank then click option'
Aroot.right
Broot.left
Croot
Dnull
Attempts:
3 left
💡 Hint
Common Mistakes
Starting from root.left skips the root node which might be the minimum.
Starting from root.right goes to the right subtree which has larger values.
2fill in blank
medium

Complete the code to move to the left child node while searching for the minimum.

DSA Javascript
function findMin(root) {
  let current = root;
  while (current.[1] !== null) {
    current = current.left;
  }
  return current.data;
}
Drag options to blanks, or click blank then click option'
Aright
Bleft
Cnode
Dchild
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'right' instead of 'left' will go to larger values.
Using 'child' or 'node' are not valid properties.
3fill in blank
hard

Fix the error in the return statement to correctly return the minimum value.

DSA Javascript
function findMin(root) {
  let current = root;
  while (current.left !== null) {
    current = current.left;
  }
  return current.[1];
}
Drag options to blanks, or click blank then click option'
Adata
Bvalue
Cval
Dmin
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'value' or 'val' which are not defined properties.
Returning 'min' which is not a property of the node.
4fill in blank
hard

Fill both blanks to create a function that returns null if the tree is empty and finds the minimum otherwise.

DSA Javascript
function findMin(root) {
  if (root === [1]) {
    return null;
  }
  let current = root;
  while (current.[2] !== null) {
    current = current.left;
  }
  return current.data;
}
Drag options to blanks, or click blank then click option'
Anull
Bundefined
Croot
Dleft
Attempts:
3 left
💡 Hint
Common Mistakes
Checking root against undefined instead of null.
Using 'right' instead of 'left' in the while loop.
5fill in blank
hard

Fill all three blanks to implement a recursive function that finds the minimum element in a BST.

DSA Javascript
function findMinRecursive(node) {
  if (node === [1]) {
    return null;
  }
  if (node.[2] === [3]) {
    return node.data;
  }
  return findMinRecursive(node.left);
}
Drag options to blanks, or click blank then click option'
Anull
Bundefined
Dleft
Attempts:
3 left
💡 Hint
Common Mistakes
Using undefined instead of null for checks.
Checking right child instead of left child.