Question

1.
2.
3.
4.
Answer (Detailed Solution Below)

Option 2 : Copy the next node's data into it and delete the next node / अगले नोड का डेटा इसमें कॉपी करें और अगले नोड को हटा दें

Advertisement

Detailed Solution

सही उत्तर Copy the next node's data into it and delete the next node / अगले नोड का डेटा इसमें कॉपी करें और अगले नोड को हटा दें है।

Key Points
Helpful?
PrepSnapprepsnap.in • Part -A

Question:

In a singly linked list, you hold a pointer to a node (not the last node) but not to the head. The standard O(1) trick to delete that node is to: / एकल लिंक्ड सूची में आपके पास एक नोड का पॉइंटर है (अंतिम नोड नहीं) परंतु हेड का नहीं। उस नोड को हटाने की मानक O(1) युक्ति है:

1.
Traverse from the node to find the head, then delete normally / हेड खोजने के लिए नोड से भ्रमण करें, फिर सामान्य रूप से हटाएँ
2.
Copy the next node's data into it and delete the next node / अगले नोड का डेटा इसमें कॉपी करें और अगले नोड को हटा दें
3.
It is impossible without the head pointer / हेड पॉइंटर के बिना यह असंभव है
4.
Set its data to NULL and leave the link unchanged / इसका डेटा NULL कर दें और लिंक अपरिवर्तित छोड़ दें

Correct Answer: Copy the next node's data into it and delete the next node / अगले नोड का डेटा इसमें कॉपी करें और अगले नोड को हटा दें

Since the predecessor is unreachable, copy the successor's payload into the target node and bypass/delete the successor — O(1) time, though the trick fails for the tail node. / पूर्ववर्ती नोड अपहुँच होने से, उत्तरवर्ती नोड का डेटा लक्ष्य नोड में कॉपी करें और उत्तरवर्ती को बायपास करके हटा दें — O(1) समय, यद्यपि यह युक्ति अंतिम नोड पर विफल होती है।

Downloaded from PrepSnap (prepsnap.in)