Complete the code to insert a new node in the BST when the tree is empty.
if (root == null) { root = new Node([1]); return root; }
When the tree is empty, we create a new node with the given value and assign it as the root.
Complete the code to decide to insert the new value in the left subtree.
if (value [1] root.Data) { root.Left = Insert(root.Left, value); }
If the value to insert is less than the current node's data, we insert it into the left subtree.
Fix the error in the recursive call to insert the new value in the right subtree.
else if (value [1] root.Data) { root.Right = Insert(root.Right, value); }
If the value is greater than the current node's data, insert it into the right subtree.
Fill both blanks to complete the Insert method that returns the updated root after insertion.
public Node Insert(Node root, int value)
{
if (root == null)
root = new Node([1]);
else if (value [2] root.Data)
root.Left = Insert(root.Left, value);
else
root.Right = Insert(root.Right, value);
return root;
}The method creates a new node with the value if root is null, then inserts recursively to left if value is less than root data.
Fill all three blanks to complete the Insert method with correct comparisons and return.
public Node Insert(Node root, int value)
{
if (root == null)
root = new Node([1]);
else if (value [2] root.Data)
root.Left = Insert(root.Left, value);
else if (value [3] root.Data)
root.Right = Insert(root.Right, value);
return root;
}The Insert method creates a new node with the value if root is null, inserts to left if value is less, to right if value is greater, and returns the root.
