QUESTION 56 Which one of the step given in options is not performed to delete a node form...
Qualcomm technical mcq question, verified with a worked answer. Free to practise - no sign-up.
QUESTION 56
Which one of the step given in options is not performed to delete a node form the singly linked list?
Show answer & explanation
When deleting a node from a singly linked list, you must: (1) find the previous node, (2) redirect the previous node's next pointer to skip the deleted node, and (3) free the deleted node's memory. Changing the next pointer of the node being deleted is unnecessary because that node is about to be deallocated anyway and no longer part of the list.
Step-by-step Derivation:
Standard singly linked list deletion algorithm:
- Locate the previous node (option B) — necessary to access and modify its next pointer.
- Update previous node's next pointer to point to the node after the deleted node (option D) — this removes the node from the chain.
- Free the memory of the deleted node (option A) — prevents memory leak.
- Changing the next pointer of the deleted node itself (option C) — UNNECESSARY because the node is being removed from the list and deallocated. Its internal state is irrelevant after deletion.
Example:
Before deletion: prev -> [nodeToDelete] -> next
After: prev -> next
We never modify nodeToDelete's next pointer; we only redirect prev's next pointer.