A Binary Search Tree is a tree data structure where each node has at most two children. For every node, all nodes in its left subtree have smaller values, and all nodes in its right subtree have larger values.
Click to reveal answer
beginner
In a BST, where is the maximum element located?
The maximum element is located at the rightmost node of the BST because all values to the right are greater.
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
beginner
Why does moving right in a BST lead to the maximum element?
Because in a BST, right children always have values greater than or equal to their parent nodes, so moving right leads to larger or equal values.
Click to reveal answer
intermediate
What is the time complexity of finding the maximum element in a BST?
The time complexity is O(h), where h is the height of the BST. In the worst case (skewed tree), it can be O(n), and in a balanced tree, it is O(log n).
Click to reveal answer
Where do you find the maximum element in a BST?
AAny leaf node
BLeftmost node
CRoot node
DRightmost node
✗ 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?
AMove to the right child
BMove to the left child
CCheck the root value only
DTraverse all nodes
✗ Incorrect
You start at the root and move to the right child repeatedly to find the maximum.
If a BST has only one node, what is the maximum element?
AThe root node itself
BNo maximum element
CLeft child
DRight child
✗ Incorrect
With only one node, that node is both minimum and maximum.
What is the time complexity to find the maximum element in a balanced BST with n nodes?
AO(n)
BO(1)
CO(log n)
DO(n log n)
✗ Incorrect
In a balanced BST, height is log n, so finding max is O(log n).
What happens if you try to move right but the right child is NULL?
AYou need to move left
BYou found the maximum element
CThe tree is empty
DYou must restart from root
✗ Incorrect
If there is no right child, the current node is the maximum.
Explain how to find the maximum element in a Binary Search Tree.
Think about the BST property and where larger values are.
You got /4 concepts.
Describe the time complexity of finding the maximum element in a BST and why it depends on the tree's shape.
Consider how many right moves you make.
You got /4 concepts.
Practice
(1/5)
1. In a Binary Search Tree (BST), where is the maximum element always located?
easy
A. At any leaf node
B. At the leftmost node
C. At the rightmost node
D. At the root node
Solution
Step 1: Understand BST property
In a BST, left child nodes have smaller values and right child nodes have larger values than their parent.
Step 2: Locate maximum element
The maximum element is the rightmost node because it has no right child and is greater than all other nodes.
Final Answer:
At the rightmost node -> Option C
Quick Check:
Maximum = rightmost node [OK]
Hint: Maximum is always the rightmost node in BST [OK]
Common Mistakes:
Confusing maximum with root node
Thinking maximum is at leftmost node
Assuming maximum can be any leaf
2. Which of the following C code snippets correctly finds the maximum element in a BST?
easy
A. while(root->left != NULL) root = root->left; return root->data;
B. while(root->right != NULL) root = root->right; return root->data;
C. if(root == NULL) return INT_MIN; return root->data;
D. return root->data;
Solution
Step 1: Analyze code logic
while(root->right != NULL) root = root->right; return root->data; moves right until no right child exists, which is correct for max in BST.
Step 2: Check other options
while(root->left != NULL) root = root->left; return root->data; moves left (minimum), C returns root data without traversal, D returns root data directly.
A. It returns -1 for empty tree instead of INT_MIN
B. It should use recursion instead of loop
C. It does not check if root is NULL before accessing data
D. It traverses left instead of right to find maximum
Solution
Step 1: Analyze traversal direction
The function moves left to find max, but max is at rightmost node in BST.
Step 2: Check other issues
Returning -1 is acceptable for empty tree; checking root NULL is done; recursion is optional.
Final Answer:
It traverses left instead of right to find maximum -> Option D
Quick Check:
Max is rightmost, not leftmost [OK]
Hint: Max element is at rightmost, not leftmost node [OK]
Common Mistakes:
Confusing left and right child traversal
Ignoring NULL checks
Thinking recursion is mandatory
5. Given a BST where some nodes have duplicate values, which approach correctly finds the maximum element considering duplicates are allowed on the right subtree?