Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to find the left child of a node in a BST.
DSA C#
TreeNode leftChild = node[1];Attempts:
3 left
💡 Hint
Common Mistakes
Using 'right' instead of 'left' to access the left child.
Trying to access a non-existent 'next' property.
✗ Incorrect
The left child of a node in a BST is accessed using the 'left' property.
2fill in blank
mediumComplete the code to find the right child of a node in a BST.
DSA C#
TreeNode rightChild = node[1];Attempts:
3 left
💡 Hint
Common Mistakes
Using 'left' instead of 'right' to access the right child.
Trying to access a 'parent' property when looking for children.
✗ Incorrect
The right child of a node in a BST is accessed using the 'right' property.
3fill in blank
hardFix the error in the code to find the minimum node in a BST subtree.
DSA C#
while (current[1] != null) { current = current.left; }
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'right' instead of 'left' in the while condition.
Using 'parent' or 'next' which are not relevant here.
✗ Incorrect
To find the minimum node, traverse left children until null.
4fill in blank
hardFill both blanks to complete the code that finds the inorder successor when the node has no right child.
DSA C#
TreeNode successor = node[1]; while (successor != null && node == successor[2]) { node = successor; successor = successor.parent; }
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'left' instead of 'right' in the comparison.
Using 'next' which is not a BST property.
✗ Incorrect
We move up to the parent and check if the node is the right child to find the successor.
5fill in blank
hardFill all three blanks to complete the code that finds the inorder successor of a node in a BST.
DSA C#
if (node[1] != null) { successor = node.right; while (successor[2] != null) { successor = successor[3]; } } else { // code to find successor when no right child }
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'left' instead of 'right' to check for the right child.
Using 'parent' instead of 'left' to find the minimum node.
✗ Incorrect
If the node has a right child, the successor is the leftmost node in the right subtree.
