If *head is NULL, then temp = NULL. Accessing temp->next causes a runtime error (segmentation fault).
Step 2: Identify fix for empty list case
Need to check if *head is NULL before loop and assign newNode as head if true.
Final Answer:
Dereferencing NULL pointer when list is empty -> Option A
Quick Check:
Empty list causes NULL pointer error [OK]
Hint: Check for empty list before traversal [OK]
Common Mistakes:
Ignoring empty list case
Confusing memory leak with pointer error
Thinking missing return causes runtime error
5. You need to store a large number of elements where insertions and deletions happen frequently at random positions. Which data structure is more suitable and why?
A) Array because it uses less memory
B) Linked List because it allows efficient insertions and deletions
C) Array because it provides faster random access
D) Linked List because it uses contiguous memory
hard
A. Array because it uses less memory
B. Linked List because it uses contiguous memory
C. Array because it provides faster random access
D. Linked List because it allows efficient insertions and deletions
Solution
Step 1: Understand insertion and deletion costs
Arrays require shifting elements for insertions/deletions at random positions, which is costly.
Step 2: Compare with linked list behavior
Linked lists allow insertions and deletions by changing pointers without shifting elements, making them efficient for frequent changes.
Final Answer:
Linked List because it allows efficient insertions and deletions -> Option D
Quick Check:
Frequent insert/delete = Linked List [OK]
Hint: Frequent insert/delete? Choose linked list [OK]
Common Mistakes:
Choosing array for frequent insertions
Thinking linked list uses contiguous memory
Ignoring cost of shifting in arrays
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.