PGDCA, BCA, B-Tech, MCA, M-Tech, B.Sc computer science राजस्थान सूचना सहायक व कंप्यूटर शिक्षक विशेष नोट्स: इस अध्याय में हम Singly Linked List Deletion: Beginning, End and Specific Key (सिंगली लिंक्ड लिस्ट डिलीशन: नोड हटाना और पॉइंटर्स एडजस्टमेंट) की संपूर्ण थ्योरी, मुख्य तकनीकी बिंदु, तुलनात्मक तालिका और विगत परीक्षाओं के पैटर्न पर आधारित 20 अति-महत्वपूर्ण बहुविकल्पीय प्रश्न (MCQs) विस्तृत हिंदी व अंग्रेजी व्याख्या सहित पढ़ेंगे।
Overview: Deleting a node from a Singly Linked List requires unlinking the target node by updating its predecessor's next pointer and explicitly calling free() to avoid memory leaks. Removing the head node executes in O(1) time, whereas deleting the last node or a specific key requires O(n) time—crucially, even with a tail pointer, deleting the last node takes O(n) because finding the second-to-last node needs forward traversal.
अध्याय सार: सिंगली लिंक्ड लिस्ट से नोड हटाने (Deletion) में पिछले नोड के next पॉइंटर से लक्ष्य नोड को बाईपास कर free() द्वारा मेमोरी मुक्त की जाती है। पहला नोड हटाना O(1) में होता है, जबकि अंतिम नोड या किसी विशिष्ट key को हटाने में O(n) समय लगता है—यहाँ तक कि tail पॉइंटर होने पर भी अंतिम नोड हटाने हेतु सेकंड-लास्ट नोड खोजने के लिए O(n) ट्रैवर्सल आवश्यक होता है।
Singly Linked List Deletion: Beginning, End and Specific Key: Detailed Notes & Architecture (सिंगली लिंक्ड लिस्ट डिलीशन: नोड हटाना और पॉइंटर्स एडजस्टमेंट)
1. Deletion from Beginning (O(1)): Temporary Pointer & Safe free() (शुरुआत से डिलीशन (O(1)): अस्थायी पॉइंटर और सुरक्षित free())
[EN] Removing the first node first checks for Underflow (if (*head == NULL) return;). Next, save the address in a temporary pointer (struct Node *temp = *head;), advance the list head (*head = (*head)->next;), and THEN release the node (free(temp);). Calling free(*head) before advancing *head is a fatal use-after-free bug because reading (*head)->next accesses already deallocated memory.
[HI] पहला नोड हटाने से पहले खाली लिस्ट (*head == NULL) की जाँच की जाती है। फिर struct Node *temp = *head में उसका पता सहेजकर *head = (*head)->next आगे बढ़ाते हैं और अंत में free(temp) चलाते हैं। ध्यान रहे कि *head को आगे बढ़ाने से पहले free(*head) चला देना गंभीर Use-After-Free त्रुटि पैदा करता है।
2. Deletion from End (O(n)): Penultimate Node & Tail-Pointer Paradox (अंत से डिलीशन (O(n)): सेकंड-लास्ट नोड व Tail पॉइंटर का विरोधाभास)
[EN] Deleting the last node handles two special cases first: empty list (*head == NULL) and single-node list ((*head)->next == NULL -> free(*head); *head = NULL;). With two or more nodes, advance curr while (curr->next->next != NULL) so curr stops at the second-to-last (penultimate) node; then free(curr->next) and set curr->next = NULL. Crucially, even if a Singly Linked List maintains BOTH head and tail pointers, deleting the last node STILL takes O(n) time because SLL lacks a backward pointer to reach the penultimate node from tail!
[HI] अंतिम नोड हटाते समय खाली लिस्ट तथा एक-नोड लिस्ट ((*head)->next == NULL -> free(*head); *head = NULL;) को अलग से संभाला जाता है। दो या अधिक नोड्स होने पर while (curr->next->next != NULL) से ठीक पहले वाले नोड पर रुककर free(curr->next) और curr->next = NULL करते हैं। परीक्षा का अत्यंत महत्वपूर्ण तथ्य यह है कि SLL में tail पॉइंटर होने पर भी अंतिम नोड हटाने में O(n) समय ही लगता है क्योंकि पिछले नोड तक जाने का बैकवर्ड पॉइंटर नहीं होता!
3. Deletion of a Specific Key (O(n)): Two-Pointer (prev, curr) Pattern (विशिष्ट Key द्वारा डिलीशन (O(n)): दो-पॉइंटर (prev, curr) विधि)
[EN] To delete the first occurrence of key, check if *head == NULL; next check whether the head node itself matches ((*head)->data == key), delegating to beginning-deletion so head updates cleanly. Otherwise, maintain prev = *head and curr = (*head)->next, advancing both while (curr != NULL && curr->data != key). If curr != NULL (key found), unlink via prev->next = curr->next and free(curr); if curr == NULL, the key was absent and the list remains unchanged.
[HI] किसी विशिष्ट key वाला नोड हटाने हेतु पहले *head == NULL और फिर पहले नोड (*head->data == key) की जाँच की जाती है। यदि key आगे हो, तो दो पॉइंटर्स prev = *head और curr = (*head)->next से लूप चलाते हैं। जब curr->data == key मिले, तो prev->next = curr->next जोड़कर free(curr) चलाते हैं; यदि curr == NULL हो जाए तो इसका अर्थ है कि key लिस्ट में मौजूद नहीं है।
4. O(1) Direct-Pointer Delete Trick, Limitations & Complete List Destruction (O(1) डायरेक्ट-पॉइंटर डिलीशन ट्रिक, सीमाएं व पूरी लिस्ट डिलीट करना)
[EN] Given ONLY a direct pointer ptr to a non-tail node (no head pointer given), you can delete ptr in O(1) time by copying ptr->next->data into ptr->data, saving temp = ptr->next, setting ptr->next = temp->next, and freeing temp—though this trick FAILS completely if ptr is the tail node (since ptr->next is NULL and the predecessor's next cannot be updated). Also, freeing an entire linked list safely in O(n) requires saving nxt = curr->next BEFORE calling free(curr).
[HI] यदि बिना head दिए केवल किसी मध्य नोड का पॉइंटर ptr मिले, तो ptr->next का डेटा ptr में कॉपी कर ptr->next को बाईपास व free करके O(1) में डिलीशन हो सकता है—परंतु यह ट्रिक अंतिम (Tail) नोड पर काम नहीं करती। इसी प्रकार पूरी लिंक्ड लिस्ट को साफ करने के लिए हमेशा free(curr) चलाने से पहले nxt = curr->next को बचाना आवश्यक है।
Syntax, Formula & Technical Example (Singly Linked List Deletion: Beginning, End and Specific Key)
void deleteKey(struct Node **head, int key) {
if (*head == NULL) return; // Underflow guard
struct Node *curr = *head, *prev = NULL;
if (curr->data == key) { // Key at head node
*head = curr->next; free(curr); return;
}
while (curr != NULL && curr->data != key) { prev = curr; curr = curr->next; }
if (curr == NULL) return; // Key not found
prev->next = curr->next; // Bypass target node
free(curr); // Release heap memory
}
Singly Linked List Deletion: Beginning, End and Specific Key Quick Reference & Comparison Table
| Deletion Scenario | Time Complexity (SLL) | Pointer Adjustment & Edge Rule |
|---|---|---|
| Delete First Node | O(1) constant time | Save temp = head; move head = head->next; free(temp) |
| Delete Last Node | O(n) even with tail pointer | Must traverse to penultimate node so its next becomes NULL |
| Delete by Specific Key | O(n) search + O(1) unlink | Handle head match separately; track prev and curr pointers |
| Delete via Direct Pointer | O(1) data-copy trick (non-tail) | Copies ptr->next data and frees ptr->next; fails on tail |
Singly Linked List Deletion: Beginning, End and Specific Key Top 20 Bilingual MCQs with Answers
Q1. What is the time complexity of deleting the FIRST node from a Singly Linked List of n nodes?
(n नोड्स वाली सिंगली लिंक्ड लिस्ट से पहला नोड हटाने (Delete Beginning) की टाइम कॉम्प्लेक्सिटी क्या होती है?)
(A) O(1)
(B) O(n)
(C) O(log n)
(D) O(n^2)
Correct Answer: (A)
[EN] Moving head to head->next and freeing the saved first node requires only constant O(1) operations.
[HI] head को head->next पर ले जाकर पुराने पहले नोड को free() करने में केवल स्थिर O(1) समय लगता है।
Q2. What is the worst-case time complexity to delete the LAST node of a Singly Linked List that maintains BOTH head and tail pointers?
(यदि एक सिंगली लिंक्ड लिस्ट में head और tail दोनों पॉइंटर रखे हों, तो अंतिम नोड को हटाने (Delete End) की टाइम कॉम्प्लेक्सिटी क्या होगी?)
(A) O(log n)
(B) O(1)
(C) O(n log n)
(D) O(n)
Correct Answer: (D)
[EN] Even with tail pointing to the last node, you still need to update the second-to-last node's next to NULL, which requires O(n) forward traversal from head.
[HI] tail पॉइंटर होने पर भी अंतिम से ठीक पहले वाले नोड (Penultimate Node) का next = NULL करने के लिए head से O(n) ट्रैवर्सल करना पड़ता है।
Q3. Which data structure enables O(1) deletion of the LAST node when a tail pointer is maintained (unlike Singly Linked List)?
(SLL के विपरीत किस डेटा स्ट्रक्चर में tail पॉइंटर होने पर अंतिम नोड का डिलीशन O(1) में संभव हो जाता है?)
(A) Static Contiguous Array without knowing length
(B) Doubly Linked List (DLL)
(C) Stack implemented over Singly Linked List without tail
(D) Binary Search Tree without parent pointers
Correct Answer: (B)
[EN] In a Doubly Linked List, tail->prev directly locates the second-to-last node in O(1) time.
[HI] डबली लिंक्ड लिस्ट (DLL) में tail->prev पॉइंटर सीधे सेकंड-लास्ट नोड पर O(1) में पहुँचा देता है।
Q4. What serious error occurs if a programmer writes: free(*head); *head = (*head)->next; when deleting the first node?
(पहला नोड हटाते समय यदि free(*head); के बाद *head = (*head)->next; लिखा जाए, तो कौन सी त्रुटि होती है?)
(A) Automatic deletion of the entire list cleanly
(B) Use-after-free: reading (*head)->next accesses already deallocated heap memory
(C) Double free of the second node
(D) Memory leak of the second node only
Correct Answer: (B)
[EN] Once free(*head) executes, reading (*head)->next triggers undefined behavior; always save temp = *head and advance *head BEFORE calling free(temp).
[HI] free(*head) के बाद वह ब्लॉक अमान्य हो जाता है, इसलिए (*head)->next पढ़ना Use-After-Free बग उत्पन्न करता है; पहले *head आगे बढ़ाएं फिर free करें।
Q5. What happens if deleteBegin() executes *head = (*head)->next; WITHOUT saving and calling free() on the original first node?
(यदि पहला नोड हटाते समय बिना free() चलाए केवल *head = (*head)->next; लिख दिया जाए, तो क्या होगा?)
(A) Segmentation fault on the next insertion
(B) C runtime garbage collector frees it immediately
(C) The node moves automatically to the end of the list
(D) Memory leak of the bypassed first node
Correct Answer: (D)
[EN] Skipping free() leaves the detached node allocated permanently on the heap with no remaining pointer referencing it.
[HI] free() न चलाने पर अलग हुआ पुराना नोड हीप में बिना किसी पॉइंटर के फंसा रह जाएगा, जिससे मेमोरी लीक होगा।
Q6. During deleteEnd() on a Singly Linked List with at least 2 nodes, which loop condition stops curr right at the second-to-last (penultimate) node?
(कम से कम 2 नोड्स वाली SLL में अंतिम नोड हटाने हेतु सेकंड-लास्ट नोड पर रुकने के लिए सही while शर्त कौन सी है?)
(A) while (curr->next->next != NULL)
(B) while (curr->data != NULL)
(C) while (curr != NULL)
(D) while (curr->next != NULL)
Correct Answer: (A)
[EN] When curr is at the second-to-last node, curr->next is the tail node and curr->next->next is NULL, terminating the loop cleanly.
[HI] सेकंड-लास्ट नोड पर पहुँचने पर curr->next अंतिम नोड होता है और curr->next->next == NULL होने से लूप वहीं रुक जाता है।
Q7. What happens in deleteEnd() if you run while (curr->next->next != NULL) without checking whether the list has 0 or 1 node?
(यदि 0 या 1 नोड वाली लिस्ट पर बिना अलग से जाँच किए सीधे while (curr->next->next != NULL) चला दिया जाए, तो क्या होगा?)
(A) It swaps head and tail pointers
(B) Segmentation fault / NULL pointer dereference
(C) It returns safely with no action
(D) It deletes the single node cleanly
Correct Answer: (B)
[EN] When head == NULL, curr->next crashes; when there is 1 node (head->next == NULL), evaluating curr->next->next dereferences NULL.
[HI] 0 नोड पर curr->next और 1 नोड पर curr->next->next NULL को डीरेफरेंस करके क्रैश (Segmentation Fault) पैदा कर देगा।
Q8. In deleteKey(head, key), why is it important to check if (curr == NULL) right after the while (curr != NULL && curr->data != key) loop?
(deleteKey फंक्शन में लूप के बाद if (curr == NULL) की जाँच करना क्यों अनिवार्य है?)
(A) Because prev becomes equal to tail automatically
(B) Because if the key does not exist in the list, curr reaches NULL and prev->next = curr->next would crash
(C) Because free(NULL) causes an immediate fatal crash
(D) Because curr == NULL means key was at the first node
Correct Answer: (B)
[EN] When key is absent, curr walks off the end to NULL; attempting curr->next without checking curr == NULL causes a segmentation fault.
[HI] यदि key लिस्ट में न हो तो curr अंत में NULL हो जाता है; जाँच के बिना curr->next पढ़ने से प्रोग्राम क्रैश हो जाएगा।
Q9. Given ONLY a direct pointer ptr to an internal (non-tail) node of a Singly Linked List (head is NOT given), how fast can you delete ptr?
(यदि head पॉइंटर दिए बिना केवल बीच के किसी नोड (अंतिम नहीं) का सीधा पॉइंटर ptr दिया जाए, तो उसे कम से कम कितने समय में हटाया जा सकता है?)
(A) O(log n) via pointer bisection
(B) Impossible unless it is a circular list
(C) O(n) because you must always start from head
(D) O(1) by copying ptr->next->data into ptr and freeing ptr->next
Correct Answer: (D)
[EN] Since ptr is not the tail, copying the successor's data and bypassing/freeing ptr->next effectively removes ptr's value in O(1).
[HI] ptr से अगले नोड का डेटा ptr में कॉपी कर ptr->next को बाईपास व free करने से यह डिलीशन O(1) में हो जाता है।
Q10. Why does the O(1) direct-pointer deletion trick (copying from ptr->next) FAIL if ptr points to the LAST node of an SLL?
(SLL के बिल्कुल अंतिम (Tail) नोड का पॉइंटर ptr मिलने पर ptr->next से डेटा कॉपी करने वाली O(1) ट्रिक क्यों विफल हो जाती है?)
(A) Because C forbids freeing the tail node
(B) Because tail nodes do not reside on the heap
(C) Because the last node's data field is read-only
(D) Because ptr->next is NULL and there is no way to update the predecessor node's next pointer to NULL without traversing from head
Correct Answer: (D)
[EN] With ptr->next == NULL, no successor exists to copy from, and without a prev pointer you cannot detach ptr from its predecessor.
[HI] अंतिम नोड का ptr->next खाली (NULL) होता है और बिना पिछले नोड के पते के उसका next = NULL सेट नहीं किया जा सकता।
Q11. When deleting a node using curr->next = curr->next->next; without storing struct Node *del = curr->next; first, what happens?
(यदि struct Node *del = curr->next; को सहेजे बिना सीधे curr->next = curr->next->next; लिख दिया जाए, तो क्या होगा?)
(A) The bypassed node becomes unreachable and leaks memory on the heap
(B) curr itself gets freed instead
(C) The bypassed node is automatically freed by C
(D) The list becomes circular
Correct Answer: (A)
[EN] Once curr->next skips over the target node, its heap address is lost and free() can no longer be called on it.
[HI] बाईपास किए गए नोड का पता खो जाने से उस पर free() नहीं चल पाएगा और वह मेमोरी लीक बन जाएगा।
Q12. How do you safely delete and free EVERY node of an entire Singly Linked List without use-after-free bugs?
(बिना Use-After-Free त्रुटि के पूरी सिंगली लिंक्ड लिस्ट के सभी नोड्स को मुक्त (Free) करने का सही तरीका क्या है?)
(A) Run while (curr != NULL) { free(curr); curr = curr->next; }
(B) Save nxt = curr->next before calling free(curr), then assign curr = nxt in a loop until NULL, finally setting head = NULL
(C) Set head = NULL directly without calling free()
(D) Call free(head) once—it recursively frees all linked nodes automatically
Correct Answer: (B)
[EN] Saving the next address before freeing the current node prevents reading freed memory and frees every heap node in O(n) time.
[HI] हर कदम पर पहले nxt = curr->next सहेजकर free(curr) चलाएं और अंत में head = NULL करें; केवल free(head) बाकी नोड्स को मुक्त नहीं करता।
Q13. What dangling pointer hazard arises when deleting the last node in an SLL that tracks both head and tail?
(यदि head व tail दोनों पॉइंटर हों और अंतिम नोड को free() करके हटाया जाए, तो किस पॉइंटर के डैंगलिंग होने का खतरा रहता है?)
(A) malloc() fails on the next call
(B) head->data automatically becomes garbage
(C) tail must be explicitly updated to the new last node (or NULL if empty), otherwise tail points to freed memory
(D) The second node becomes a self-loop
Correct Answer: (C)
[EN] Forgetting to update tail = prev (or tail = NULL for single node) leaves tail pointing to the freed node.
[HI] अंतिम नोड हटाने के बाद यदि tail को नए अंतिम नोड (या खाली होने पर NULL) पर अपडेट न किया जाए, तो tail डैंगलिंग पॉइंटर बन जाता है।
Q14. What happens when deleteKey(head, 20) runs on list 10 -> 20 -> 30 -> 20 -> NULL using a standard single-key deletion routine?
(लिस्ट 10 -> 20 -> 30 -> 20 -> NULL पर मानक सिंगल-की डिलीशन deleteKey(head, 20) चलाने से परिणाम क्या होगा?)
(A) Both 20s are deleted, yielding 10 -> 30 -> NULL
(B) Only the first occurrence of 20 is deleted, yielding 10 -> 30 -> 20 -> NULL
(C) Only the last 20 is deleted, yielding 10 -> 20 -> 30 -> NULL
(D) It crashes because duplicates are forbidden in SLL
Correct Answer: (B)
[EN] Standard deleteKey stops and returns after unlinking the first matching node; deleting all occurrences requires continuing traversal without returning early.
[HI] मानक deleteKey केवल पहली बार मिलने वाले 20 को हटाकर रुक जाता है, जिससे लिस्ट 10 -> 30 -> 20 -> NULL बनती है।
Q15. What is the time complexity to delete an element at 1-based position k inside a Singly Linked List of n nodes?
(n नोड्स वाली सिंगली लिंक्ड लिस्ट में 1-आधारित स्थान k का नोड हटाने की वर्स्ट-केस टाइम कॉम्प्लेक्सिटी क्या होती है?)
(A) O(n^2)
(B) O(1) for all positions k
(C) O(n)
(D) O(log n)
Correct Answer: (C)
[EN] Reaching predecessor node (k - 1) takes O(k) steps, which is O(n) in the worst case when k = n.
[HI] k-वें नोड के पिछले नोड (k - 1) तक पहुँचने में O(k) और अंतिम नोड होने पर O(n) समय लगता है।
Q16. Which statement is NOT true about Singly Linked List deletion?
(सिंगली लिंक्ड लिस्ट डिलीशन के बारे में इनमें से कौन सा कथन असत्य (NOT true) है?)
(A) Deleting the first node takes O(1) time
(B) Deleting the last node takes O(n) time even with a tail pointer
(C) Empty-list underflow occurs when trying to delete with head == NULL
(D) Calling free(head) once automatically deallocates every node in the entire linked list
Correct Answer: (D)
[EN] free(head) only frees the single struct Node block at head; it never follows next pointers, so remaining nodes leak unless freed in a loop.
[HI] एक बार free(head) चलाने से केवल पहला नोड ही मुक्त होता है, पूरी लिस्ट अपने आप मुक्त नहीं होती—इसके लिए लूप चलाना जरूरी है।
Q17. Within Singly Linked List Deletion: Beginning, End and Specific Key, which deletion scenario directly maps to: "O(1) constant time"?
(Singly Linked List Deletion: Beginning, End and Specific Key में कौन सा Deletion Scenario सीधे "O(1) constant time" से संबंधित है?)
(A) Delete by Specific Key
(B) Delete via Direct Pointer
(C) Delete First Node
(D) Delete Last Node
Correct Answer: (C)
[EN] In Singly Linked List Deletion: Beginning, End and Specific Key, 'Delete First Node' handles 'O(1) constant time' (Save temp = head; move head = head->next; free(temp)).
[HI] Singly Linked List Deletion: Beginning, End and Specific Key में 'Delete First Node' का कार्य/विवरण 'O(1) constant time' (Save temp = head; move head = head->next; free(temp)) है।
Q18. Which option accurately describes 'Delete Last Node' in Singly Linked List Deletion: Beginning, End and Specific Key?
(Singly Linked List Deletion: Beginning, End and Specific Key के संदर्भ में 'Delete Last Node' की सही विशेषता कौन सी है?)
(A) O(n) search + O(1) unlink
(B) O(n) even with tail pointer
(C) O(1) constant time
(D) O(1) data-copy trick (non-tail)
Correct Answer: (B)
[EN] 'Delete Last Node' provides 'O(n) even with tail pointer' — key point: Must traverse to penultimate node so its next becomes NULL.
[HI] 'Delete Last Node' का मुख्य विवरण 'O(n) even with tail pointer' है (Must traverse to penultimate node so its next becomes NULL)।
Q19. In Singly Linked List Deletion: Beginning, End and Specific Key, identify the correct parameter for the specification: "O(n) search + O(1) unlink".
(Singly Linked List Deletion: Beginning, End and Specific Key में "O(n) search + O(1) unlink" विवरण किस विकल्प के लिए सही है?)
(A) Delete via Direct Pointer
(B) Delete Last Node
(C) Delete by Specific Key
(D) Delete First Node
Correct Answer: (C)
[EN] 'Delete by Specific Key' corresponds to 'O(n) search + O(1) unlink' (Handle head match separately; track prev and curr pointers).
[HI] 'Delete by Specific Key' का संबंध 'O(n) search + O(1) unlink' (Handle head match separately; track prev and curr pointers) से है।
Q20. Considering Singly Linked List Deletion: Beginning, End and Specific Key, what key behavior defines 'Delete via Direct Pointer'?
(Singly Linked List Deletion: Beginning, End and Specific Key में 'Delete via Direct Pointer' की मुख्य भूमिका या मान क्या है?)
(A) O(n) search + O(1) unlink
(B) O(n) even with tail pointer
(C) O(1) constant time
(D) O(1) data-copy trick (non-tail)
Correct Answer: (D)
[EN] 'Delete via Direct Pointer' represents 'O(1) data-copy trick (non-tail)' (Copies ptr->next data and frees ptr->next; fails on tail).
[HI] 'Delete via Direct Pointer' का अर्थ/मान 'O(1) data-copy trick (non-tail)' है (Copies ptr->next data and frees ptr->next; fails on tail)।
Singly Linked List Deletion: Beginning, End and Specific Key — Exam FAQs
Q1: Why does deleting the last node of a Singly Linked List still take O(n) time even when a tail pointer exists?
tail पॉइंटर मौजूद होने पर भी सिंगली लिंक्ड लिस्ट का अंतिम नोड हटाने में O(n) समय क्यों लगता है?
[EN] Although tail lets us reach the last node immediately, removing it requires updating the SECOND-TO-LAST node's next pointer to NULL and moving tail back to it. Because SLL nodes have no prev pointer, finding that second-to-last node forces an O(n) walk from head.
[HI] अंतिम नोड हटाने के बाद सेकंड-लास्ट नोड का next = NULL करना और tail को पीछे लाना जरूरी होता है। चूँकि SLL में पीछे जाने वाला पॉइंटर नहीं होता, इसलिए सेकंड-लास्ट नोड तक पहुँचने हेतु head से O(n) ट्रैवर्सल करना ही पड़ता है।
Q2: Why does deleting a node in C require calling free() instead of just unlinking prev->next?
C में केवल prev->next बदलकर नोड को बाईपास कर देना पर्याप्त क्यों नहीं है और free() चलाना क्यों आवश्यक है?
[EN] Unlinking only removes the node from logical list traversal; the dynamically allocated bytes remain permanently reserved on the heap until free() returns them, causing a memory leak.
[HI] पॉइंटर बाईपास करने से नोड केवल लिस्ट के रास्ते से हटता है, लेकिन हीप मेमोरी में वह जगह तब तक फंसी रहती है जब तक free() न चलाया जाए—अन्यथा मेमोरी लीक होता है।
Q3: What special edge cases must every SLL deletion function test?
सिंगली लिंक्ड लिस्ट के किसी भी डिलीशन फंक्शन में कौन से विशेष एज-केस (Edge Cases) जरूर जाँचे जाने चाहिए?
[EN] Always guard against (1) empty list (head == NULL), (2) single-node list (head->next == NULL), (3) deleting the head node itself, and (4) key/position not found (curr == NULL).
[HI] हमेशा चार स्थितियाँ जाँचें: (1) खाली लिस्ट (head == NULL), (2) केवल एक नोड वाली लिस्ट, (3) पहला नोड (head) हटने की स्थिति, और (4) key या स्थान का न मिलना।
Post a Comment
Post a Comment