A. root is uninitialized pointer; fix by allocating memory with malloc.
B. root should be a struct, not a pointer; fix by declaring 'Node root;' instead.
C. Missing semicolon after struct definition; add semicolon.
D. Cannot assign NULL to pointers; use 0 instead.
Solution
Step 1: Identify pointer initialization issue
root is declared as a pointer but not assigned memory, so accessing root->data causes undefined behavior.
Step 2: Fix by allocating memory
Use malloc to allocate memory before accessing members: root = malloc(sizeof(Node));
Final Answer:
root is uninitialized pointer; fix by allocating memory with malloc. -> Option A
Quick Check:
Pointer must point to allocated memory = C [OK]
Hint: Always malloc before using pointer to struct [OK]
Common Mistakes:
Using pointer without allocation
Confusing pointer and struct variable
Ignoring memory allocation errors
5. You want to represent a company's organizational chart where each manager can have multiple employees reporting to them. Why is a tree a better data structure than arrays or linked lists for this, and how would you implement it in C?
hard
A. Arrays are better because they allow random access; implement with a large array of employees.
B. Trees represent hierarchical relationships naturally; implement using nodes with data and a list of child pointers.
C. Linked lists are better because they are simple; implement with a single linked list of all employees.
D. Trees are not suitable; use hash tables instead for fast lookup.
Solution
Step 1: Understand the hierarchical nature of organizational charts
Each manager can have multiple employees, forming a tree-like structure with parent-child relationships.
Step 2: Compare data structures for this use case
Arrays and linked lists are linear and cannot represent multiple children per node efficiently; trees allow multiple children per node naturally.
Step 3: Implementation approach in C
Use a struct with data and a dynamic array or linked list of pointers to child nodes to represent multiple employees under a manager.
Final Answer:
Trees represent hierarchical relationships naturally; implement using nodes with data and a list of child pointers. -> Option B
Quick Check:
Hierarchy needs trees with child lists = A [OK]
Hint: Use trees with child lists for multi-level hierarchy [OK]
Common Mistakes:
Trying to use arrays for hierarchical data
Using single linked list for multi-child nodes
Ignoring the need for multiple children pointers
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.