0
0
DSA Javascriptprogramming~5 mins

BST Find Minimum Element in DSA Javascript - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a Binary Search Tree (BST)?
A BST is a tree where each node has at most two children. The left child's value is less than the parent's value, and the right child's value is greater. This helps in fast searching.
Click to reveal answer
beginner
How do you find the minimum element in a BST?
Start at the root and keep moving to the left child until there is no left child. The last node you reach is the minimum element.
Click to reveal answer
beginner
Why does moving left in a BST lead to the minimum element?
Because in a BST, left children always have smaller values than their parents, so the leftmost node holds the smallest value.
Click to reveal answer
intermediate
What is the time complexity of finding the minimum element in a BST?
The time complexity is O(h), where h is the height of the tree. In the best case (balanced tree), it's O(log n), and in the worst case (skewed tree), it's O(n).
Click to reveal answer
beginner
Show the JavaScript code snippet to find the minimum element in a BST.
function findMin(root) {
  if (!root) return null;
  while (root.left) {
    root = root.left;
  }
  return root.value;
}
Click to reveal answer
In a BST, where is the minimum element located?
AAt the leftmost node
BAt the rightmost node
CAt the root node
DAt any leaf node
What should you do if the BST is empty when finding the minimum element?
AThrow an error
BReturn the root value
CReturn zero
DReturn null or indicate no minimum
What is the time complexity to find the minimum element in a balanced BST with n nodes?
AO(log n)
BO(n log n)
CO(1)
DO(n)
Which of these steps is NOT part of finding the minimum element in a BST?
AStart at the root
BKeep moving to the right child
CStop when no left child exists
DReturn the last node's value
What does the function return if the BST has only one node?
AThe value of the root's left child
Bnull
CThe value of the single node
DUndefined
Explain step-by-step how to find the minimum element in a Binary Search Tree.
Think about how BST organizes smaller values on the left.
You got /4 concepts.
    Write a simple JavaScript function to find the minimum element in a BST and explain how it works.
    Use a while loop to move left until no more left child.
    You got /4 concepts.