Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a new node with the given value.
DSA Java
Node newNode = new Node([1]);Attempts:
3 left
💡 Hint
Common Mistakes
Using 'node' or 'root' instead of the value.
Using 'null' which does not create a node with the value.
✗ Incorrect
We create a new node using the value to insert into the BST.
2fill in blank
mediumComplete the code to check if the root is empty before inserting.
DSA Java
if (root == [1]) { root = newNode; return root; }
Attempts:
3 left
💡 Hint
Common Mistakes
Checking if root equals newNode instead of null.
Using root itself in the condition.
✗ Incorrect
We check if root is null to know if the tree is empty.
3fill in blank
hardFix the error in the recursive insert call to the left subtree.
DSA Java
if (value < root.data) { root.left = [1](root.left, value); }
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong method names like insertNode or addNode.
Forgetting to assign the result back to root.left.
✗ Incorrect
The method name is 'insert' for recursive calls.
4fill in blank
hardFill both blanks to complete the recursive insert call to the right subtree.
DSA Java
if (value > root.data) { root.[1] = insert(root.[2], value); }
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'left' instead of 'right' for the right subtree.
Using 'root' or 'node' which are incorrect here.
✗ Incorrect
We insert into the right subtree and assign back to root.right.
5fill in blank
hardFill all three blanks to complete the insert method signature and return statement.
DSA Java
public static Node [1](Node [2], int [3]) { // method body return root; }
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong method names like 'add'.
Using incorrect parameter names.
✗ Incorrect
The method is named 'insert', takes 'root' node and 'value' to insert.
