Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to return the left child of the current node.
DSA Typescript
return node[1];
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Returning node.right instead of node.left
Returning node.value instead of a node reference
✗ Incorrect
In a BST, the minimum element is found by going to the left child repeatedly. So, we return node.left.
2fill in blank
mediumComplete the code to check if the current node has no left child.
DSA Typescript
if (node[1] === null) {
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Checking node.right instead of node.left
Comparing node.value to null
✗ Incorrect
If node.left is null, it means this node is the smallest in the BST.
3fill in blank
hardFix the error in the recursive call to find the minimum node.
DSA Typescript
return findMin(node[1]);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using node.right in recursion
Using node.value instead of a node reference
✗ Incorrect
To find the minimum, we recursively call findMin on the left child.
4fill in blank
hardFill both blanks to complete the iterative search for the minimum node.
DSA Typescript
while (current[1] !== null) { current = current[2]; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using right child in the loop condition or update
Using node.value instead of node reference
✗ Incorrect
We keep moving to the left child until there is no left child left.
5fill in blank
hardFill all three blanks to complete the function that finds the minimum node recursively.
DSA Typescript
function findMin(node: TreeNode | null): TreeNode | null {
if (node === null || node[1] === null) {
return node;
}
return findMin(node[2]);
}
const minNode = findMin(root[3]); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using node.right instead of node.left
Adding extra property after root in the last blank
✗ Incorrect
We check if node.left is null to find the minimum, then recurse on node.left. The last blank is empty because root is already the node.