Question

A C function insert(Node* root, int data) for a BST. #include typedef struct Node {     int data;     struct Node *left, *right; } Node; Node* newNode(int data) {     Node* temp = (Node*)malloc(sizeof(Node));     temp->data = data;     temp->left = temp->right = NULL;     return temp; } Node* insert(Node* root, int data) {     if (root == NUL

  • L {         return newNode(data);     }     if (data < root->data) {         root->left = insert(root->left, data);     } else { // Handles data >= root->data         root->right = insert(root->right, data);     }     // Bug: Missing 'return root;' here } If this insert function is used to build a BST (e.g., root = insert(root, 50); root = insert(root, 30);), what is the most critical issue that will arise due to the missing return root; statement?
A The tree will become unbalanced.
B Duplicate values will not be handled correctly.
C The function will return an undefined value, potentially corrupting tree links or causing a crash.
D A memory leak will occur because malloc is used without free.
E The else branch will never be executed.
Practice Next

Hey! Ask a query