Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to return the minimum value in the BST.
DSA C#
public int FindMin(Node root) {
if (root == null) return -1;
Node current = root;
while (current.[1] != null) {
current = current.left;
}
return current.value;
}Attempts:
3 left
💡 Hint
Common Mistakes
Checking current.right instead of current.left
Returning root.value without traversal
Using recursion instead of iteration here
✗ Incorrect
In a BST, the minimum element is found by going as far left as possible. So we check current.left in the loop.
2fill in blank
mediumComplete the code to recursively find the minimum value in the BST.
DSA C#
public int FindMinRecursive(Node root) {
if (root == null) return -1;
if (root.[1] == null) return root.value;
return FindMinRecursive(root.left);
}Attempts:
3 left
💡 Hint
Common Mistakes
Checking right child instead of left
Not handling null root
Returning root.value without checking children
✗ Incorrect
If the left child is null, the current node is the minimum. Otherwise, recurse left.
3fill in blank
hardFix the error in the code to correctly find the minimum value iteratively.
DSA C#
public int FindMinIterative(Node root) {
if (root == null) return -1;
Node current = root;
while (current.left != [1]) {
current = current.left;
}
return current.value;
}Attempts:
3 left
💡 Hint
Common Mistakes
Using root instead of null
Using current instead of null
Using this keyword incorrectly
✗ Incorrect
The loop should continue while current.left is not null to reach the leftmost node.
4fill in blank
hardFill both blanks to create a method that returns the minimum value or -1 if tree is empty.
DSA C#
public int GetMinValue(Node root) {
if (root == [1]) return [2];
Node current = root;
while (current.left != null) {
current = current.left;
}
return current.value;
}Attempts:
3 left
💡 Hint
Common Mistakes
Returning 0 instead of -1 for empty tree
Checking root == root instead of root == null
✗ Incorrect
If root is null, return -1 to indicate empty tree.
5fill in blank
hardFill all three blanks to implement a recursive method that returns the minimum value or -1 if empty.
DSA C#
public int MinValue(Node root) {
if (root == [1]) return [2];
if (root.left == [3]) return root.value;
return MinValue(root.left);
}Attempts:
3 left
💡 Hint
Common Mistakes
Returning 0 instead of -1 for empty tree
Not checking left child before recursion
✗ Incorrect
Check if root is null to return -1; if left child is null, root is minimum.
