A Binary Search Tree is a tree data structure where each node has at most two children. For every node, all values in the left subtree are smaller, and all values in the right subtree are larger.
Click to reveal answer
beginner
In a BST, where is the maximum element located?
The maximum element is always found at the rightmost node of the BST because values increase as you move right.
Click to reveal answer
beginner
What is the basic approach to find the maximum element in a BST?
Start at the root and keep moving to the right child until there is no right child. The last node you reach is the maximum element.
Click to reveal answer
intermediate
Why is finding the maximum element in a BST efficient?
Because you only follow the right children, the search takes time proportional to the height of the tree, which is faster than checking every node.
Click to reveal answer
beginner
What happens if the BST is empty when trying to find the maximum element?
If the BST is empty (no nodes), there is no maximum element, so the function should handle this case, often by returning null or indicating the tree is empty.
Click to reveal answer
Where do you find the maximum element in a BST?
AAt the leftmost node
BAt the rightmost node
CAt the root node
DAt any leaf node
✗ Incorrect
The maximum element is at the rightmost node because values increase to the right.
What should you do if the BST is empty when finding the maximum element?
AThrow an error always
BReturn the root value
CReturn zero
DReturn null or indicate empty
✗ Incorrect
If the BST is empty, there is no maximum element, so returning null or indicating the tree is empty is correct.
What is the time complexity to find the maximum element in a BST?
AO(n)
BO(1)
CO(log n)
DO(n log n)
✗ Incorrect
Finding the maximum element takes time proportional to the height of the tree, which is O(log n) for balanced BSTs.
Which direction do you move to find the maximum element in a BST?
ARight child
BBoth children
CLeft child
DUp to parent
✗ Incorrect
You move to the right child repeatedly to find the maximum element.
If a BST has only one node, what is the maximum element?
AThe root node itself
BNo maximum element
CThe left child
DThe right child
✗ Incorrect
If there is only one node, that node is both the minimum and maximum.
Explain step-by-step how to find the maximum element in a BST.
Think about the property of BST and where larger values are located.
You got /4 concepts.
Describe how to handle the case when the BST is empty while finding the maximum element.
Consider what happens if there are no nodes.
You got /3 concepts.
Practice
(1/5)
1. In a Binary Search Tree (BST), where is the maximum element always located?
easy
A. At the root node
B. At the rightmost node
C. At the leftmost node
D. At any leaf node
Solution
Step 1: Understand BST property
In a BST, left child nodes have smaller values and right child nodes have larger values compared to their parent.
Step 2: Locate maximum element
The maximum element is the largest value, so it must be the rightmost node because values increase to the right.
Final Answer:
At the rightmost node -> Option B
Quick Check:
Maximum element = rightmost node [OK]
Hint: Maximum is always the rightmost node in BST [OK]
Common Mistakes:
Thinking maximum is at the root
Confusing leftmost with maximum
Assuming maximum can be any leaf
2. Which of the following C# code snippets correctly finds the maximum element in a BST node called root?
easy
A. while (root.Left != null) { root = root.Left; } return root.Value;
B. if (root.Left == null) return root.Value; else return root.Left.Value;
C. while (root.Right != null) { root = root.Right; } return root.Value;
D. return root.Value; // root is always max
Solution
Step 1: Check traversal direction
To find max, traverse right child nodes until no more right child exists.
Step 2: Verify code correctness
while (root.Right != null) { root = root.Right; } return root.Value; uses a while loop to move right until root.Right is null, then returns root.Value, which is correct.
Final Answer:
while (root.Right != null) { root = root.Right; } return root.Value; -> Option C
Quick Check:
Traverse right until null, then return value [OK]
Hint: Traverse right child until null to find max [OK]
Common Mistakes:
Traversing left child instead of right
Returning root value without traversal
Using incorrect condition in loop
3. What will be the output of the following C# code snippet that finds the maximum element in a BST?
class Node {
public int Value;
public Node Left, Right;
public Node(int val) { Value = val; Left = Right = null; }
}
Node root = new Node(10);
root.Left = new Node(5);
root.Right = new Node(15);
root.Right.Right = new Node(20);
Node current = root;
while (current.Right != null) {
current = current.Right;
}
Console.WriteLine(current.Value);
medium
A. 5
B. 15
C. 10
D. 20
Solution
Step 1: Trace the BST structure
Root is 10, right child 15, right child of 15 is 20. So rightmost node is 20.
Step 2: Follow the loop
The loop moves current from 10 to 15, then to 20, then stops because 20.Right is null.
Final Answer:
20 -> Option D
Quick Check:
Rightmost node value = 20 [OK]
Hint: Rightmost node value is maximum [OK]
Common Mistakes:
Stopping at 15 instead of 20
Printing root value instead of max
Confusing left and right children
4. The following C# method is intended to find the maximum element in a BST. What is the error?
int FindMax(Node root) {
if (root == null) return int.MinValue;
if (root.Right == null) return root.Value;
return FindMax(root.Left);
}
medium
A. It should recurse on root.Right, not root.Left
B. It should return int.MaxValue when root is null
C. It should check root.Left instead of root.Right
D. No error, code is correct
Solution
Step 1: Analyze recursion direction
To find max, recursion must go right, but code recurses left incorrectly.
Step 2: Identify correct recursion
Change FindMax(root.Left) to FindMax(root.Right) to find max correctly.
Final Answer:
It should recurse on root.Right, not root.Left -> Option A
Quick Check:
Max found by right recursion [OK]
Hint: Max search recurses right child, not left [OK]
Common Mistakes:
Recursing left child instead of right
Returning wrong base case value
Ignoring null root check
5. Given a BST where some nodes have duplicate values, which approach correctly finds the maximum value considering duplicates?
int FindMaxWithDuplicates(Node root) {
if (root == null) return int.MinValue;
int rightMax = FindMaxWithDuplicates(root.Right);
return Math.Max(root.Value, rightMax);
}
What is the output of FindMaxWithDuplicates on this BST?
Root: 10
Left: 5
Right: 10
Right.Right: 15
Right.Right.Right: 15
hard
A. 15
B. 10
C. 5
D. Error due to duplicates
Solution
Step 1: Understand duplicate handling
The method compares current node value with max from right subtree, so duplicates do not affect max finding.
Step 2: Trace values
Right subtree max is 15 (rightmost node). Root value 10 is less than 15, so max is 15.
Final Answer:
15 -> Option A
Quick Check:
Max value with duplicates = 15 [OK]
Hint: Compare node value with right subtree max for duplicates [OK]
Common Mistakes:
Assuming duplicates cause errors
Returning first max found without comparison
Ignoring right subtree values
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.