Question discussion

In a singly linked list, a pointer p to a node that is not the last node is given, but the head of the list is not available. How can that…

1780Medium DSSSB TGT Computer Science 0 replies 1 views
0

In a singly linked list, a pointer p to a node that is not the last node is given, but the head of the list is not available. How can that node be deleted in O(1) time?

  • ASet p to NULL
  • BFree p directly without changing any link
  • CCopy the data of the next node into p's node and delete the next node
  • DIt cannot be done in less than O(n) time
Correct answer: C

Explanation

Overwriting p's data with that of its successor and unlinking the successor removes the required value without needing the predecessor.

Discussion 0

Nobody has replied yet. Start the discussion!