Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to declare a pointer to the left child node.
DSA C
struct Node {
int data;
struct Node* [1];
struct Node* right;
};Attempts:
3 left
💡 Hint
Common Mistakes
Using 'child' or 'next' which are not standard names for binary tree pointers.
✗ Incorrect
The left child pointer in a binary tree node is conventionally named 'left'.
2fill in blank
mediumComplete the code to define a function that creates a new node with given data.
DSA C
struct Node* createNode(int data) {
struct Node* newNode = (struct Node*)malloc(sizeof(struct Node));
newNode->data = data;
newNode->left = NULL;
newNode->[1] = NULL;
return newNode;
}Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect pointer names like 'child' or 'parent'.
✗ Incorrect
The right child pointer must be initialized to NULL when creating a new node.
3fill in blank
hardFix the error in the code to correctly assign the left child of a node.
DSA C
void setLeftChild(struct Node* parent, struct Node* child) {
parent->[1] = child;
}Attempts:
3 left
💡 Hint
Common Mistakes
Assigning to 'right' or 'child' which are incorrect pointer names.
✗ Incorrect
To assign the left child, use the 'left' pointer of the parent node.
4fill in blank
hardFill both blanks to declare a binary tree node struct with data and child pointers.
DSA C
struct Node {
[1] data;
struct Node* [2];
struct Node* right;
};Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong data types like 'float' or 'char' when integer is expected.
Using incorrect pointer names like 'right' for the left child.
✗ Incorrect
The data is an integer and the left child pointer is named 'left'.
5fill in blank
hardFill all three blanks to complete the function that initializes a new node with data and NULL children.
DSA C
struct Node* createNode([1] data) { struct Node* newNode = (struct Node*)malloc(sizeof(struct Node)); newNode->data = data; newNode->[2] = NULL; newNode->[3] = NULL; return newNode; }
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong data types like 'float'.
Mixing up left and right pointer names.
✗ Incorrect
The function takes an int data, and initializes left and right pointers to NULL.
