Complete the code to find the maximum value in a BST by moving to the right child.
public int FindMax(Node root) {
if (root == null) return int.MinValue;
Node current = root;
while (current.[1] != null) {
current = current.right;
}
return current.data;
}In a BST, the maximum element is found by continuously moving to the right child until no more right child exists.
Complete the code to return the maximum value found in the BST.
public int FindMax(Node root) {
if (root == null) return int.MinValue;
Node current = root;
while (current.right != null) {
current = current.right;
}
return current.[1];
}The node's value is stored in the 'data' field, which holds the integer value.
Fix the error in the code to correctly find the maximum element in the BST.
public int FindMax(Node root) {
if (root == null) return int.MinValue;
Node current = root;
while (current.[1] != null) {
current = current.left;
}
return current.data;
}To find the maximum, we must move to the right child, not the left.
Fill both blanks to complete the method that finds the maximum element in the BST.
public int FindMax(Node root) {
if (root == null) return int.MinValue;
Node current = root;
while (current.[1] != null) {
current = current.[2];
}
return current.data;
}Both blanks should be 'right' to move along the right children until the maximum is found.
Fill all three blanks to complete the method that finds the maximum element in the BST safely.
public int FindMax(Node root) {
if (root == null) return [1];
Node current = root;
while (current.[2] != null) {
current = current.[3];
}
return current.data;
}Return int.MinValue if tree is empty, then move right until no more right child exists.
