Recall & Review
beginner
What is a Binary Search Tree (BST)?
A Binary Search Tree 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 than the parent's value.
Click to reveal answer
beginner
In a BST, where is the maximum element located?
The maximum element is always found at the rightmost node because values increase as you move right.
Click to reveal answer
beginner
Why do we keep moving right to find the maximum element in a BST?
Because in a BST, all right children have values greater than their parents, so the farthest right node holds the largest value.
Click to reveal answer
intermediate
What is the time complexity to find the maximum element in a BST?
The time complexity is O(h), where h is the height of the tree. In the worst case (skewed tree), it can be O(n).
Click to reveal answer
beginner
Show the JavaScript code snippet to find the maximum element in a BST.
function findMax(root) {
if (!root) return null;
while (root.right) {
root = root.right;
}
return root.value;
}Click to reveal answer
Where do you find the maximum element in a BST?
✗ Incorrect
The maximum element is always at the rightmost node in a BST.
What is the first step to find the maximum element in a BST?
✗ Incorrect
You start by moving to the right child repeatedly to find the maximum.
What is the time complexity to find the maximum element in a balanced BST?
✗ Incorrect
In a balanced BST, height h is about log n, so time complexity is O(log n).
If a BST has only one node, what is the maximum element?
✗ Incorrect
With one node, the root itself is the maximum element.
What happens if you call findMax on an empty BST?
✗ Incorrect
The function returns null when the BST is empty.
Explain how to find the maximum element in a Binary Search Tree.
Think about where larger values are stored in a BST.
You got /4 concepts.
Write a simple JavaScript function to find the maximum value in a BST and explain its steps.
Use a while loop to traverse right children.
You got /3 concepts.