PageSourceSearch

https://pynyx.com/assets/DummyNodeMutationPage-BwSS6e_O.js

js pynyx.com collected 2026-09-30 17:41:41 UTC 23,727 bytes, 65 lines download raw bytes

1import{r as c,X as e,eg as k,dc as L,b3 as I,eh as _,ao as a,aO as S,ay as T,aE as E,et as C,cb as g,aQ as A,bY as O,an as D}from"./vendor-CdjaocVk.js";import{M,T as P}from"./MasterNotesLayout-CIe6TqV2.js";import{A as R,P as U,M as W,a as j,E as B}from"./ResourceComponents-B8njlzzY.js";import{B as u,c as l}from"./index-D1lVQEEY.js";const H=()=>[{action:"start",stepIndex:0,currId:"dummy",l1Id:"l1_1",l2Id:"l2_2",mergedList:["dummy"],reasoning:"We initialize a Sentinel Dummy Node (value 0). 'curr' starts here. 'l1' and 'l2' point to the heads of both lists."},{action:"link",stepIndex:1,currId:"dummy",l1Id:"l1_1",l2Id:"l2_2",mergedList:["dummy","l1_1"],reasoning:"Compare L1 (1) and L2 (2). Since 1 < 2, we link curr.next to L1: 'curr.next = l1'."},{action:"advance",stepIndex:2,currId:"l1_1",l1Id:"l1_3",l2Id:"l2_2",mergedList:["dummy","l1_1"],reasoning:"We advance the L1 pointer to the next node (3) and move 'curr' forward to node 1."},{action:"link",stepIndex:3,currId:"l1_1",l1Id:"l1_3",l2Id:"l2_2",mergedList:["dummy","l1_1","l2_2"],reasoning:"Compare L1 (3) and L2 (2). Since 2 < 3, we link curr.next to L2: 'curr.next = l2'."},{action:"advance",stepIndex:4,currId:"l2_2",l1Id:"l1_3",l2Id:"l2_4",mergedList:["dummy","l1_1","l2_2"],reasoning:"We advance the L2 pointer to the next node (4) and move 'curr' forward to node 2."},{action:"link",stepIndex:5,currId:"l2_2",l1Id:"l1_3",l2Id:"l2_4",mergedList:["dummy","l1_1","l2_2","l1_3"],reasoning:"Compare L1 (3) and L2 (4). Since 3 < 4, we link curr.next to L1: 'curr.next = l1'."},{action:"advance",stepIndex:6,currId:"l1_3",l1Id:null,l2Id:"l2_4",mergedList:["dummy","l1_1","l2_2","l1_3"],reasoning:"We advance L1 to null (end of L1 list) and move 'curr' forward to node 3."},{action:"link",stepIndex:7,currId:"l1_3",l1Id:null,l2Id:"l2_4",mergedList:["dummy","l1_1","l2_2","l1_3","l2_4"],reasoning:"L1 list is empty. We append the remainder of L2 to our merged list: 'curr.next = l2'."},{action:"advance",stepIndex:8,currId:"l2_4",l1Id:null,l2Id:null,mergedList:["dummy","l1_1","l2_2","l1_3","l2_4"],reasoning:"We advance L2 to null and move 'curr' forward to node 4."},{action:"done",stepIndex:9,currId:null,l1Id:null,l2Id:null,mergedList:["dummy","l1_1","l2_2","l1_3","l2_4"],reasoning:"Merging complete! The final list head is retrieved via 'dummy.next' (node 1), which returns 1 -> 2 -> 3 -> 4."}],F=()=>{const n=c.useMemo(()=>H(),[]),[r,o]=c.useState(0),[d,x]=c.useState(!1),[m]=c.useState({timer:null}),t=r>=0?n[r]:n[0],p=r>=n.length-1,h=()=>{x(!1),m.timer&&clearTimeout(m.timer)},N=()=>{r<n.length-1?o(s=>s+1):h()},y=()=>{o(0),h()},v=()=>{if(d)h();else{x(!0);const s=i=>{if(i>=n.length-1){x(!1);return}o(i+1),m.timer=setTimeout(()=>s(i+1),1800)};s(r)}},w={dummy:{val:"Dummy (0)",color:"text-[#8be9fd] border-[#8be9fd]"},l1_1:{val:"1",color:"text-[#50fa7b] border-[#50fa7b]"},l1_3:{val:"3",color:"text-[#50fa7b] border-[#50fa7b]"},l2_2:{val:"2",color:"text-[#ffb86c] border-[#ffb86c]"},l2_4:{val:"4",color:"text-[#ffb86c] border-[#ffb86c]"}};return e.jsxs("div",{className:"bg-[#0b0e14] border border-[#30363d] rounded-2xl overflow-hidden shadow-2xl font-mono relative",children:[e.jsxs("div",{className:"p-5 border-b border-[#30363d] bg-black/40 flex flex-col sm:flex-row justify-between items-start sm:items-center gap-4",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-[10px] font-black uppercase tracking-[0.4em] text-[#bd93f9]",children:"SENTINEL DUMMY NODE"}),e.jsx("div",{className:"text-sm font-bold text-white",children:"Merging Two Sorted Lists Safely"})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(u,{variant:"outline",onClick:y,className:"border-[#30363d] text-[#8b949e] font-black uppercase text-[9px] h-8 px-3",children:[e.jsx(k,{className:"w-3 h-3 mr-1"})," Reset"]}),e.jsx(u,{onClick:v,disabled:p,className:l("font-black uppercase text-[9px] h-8 px-4",d?"bg-[#ff79c6] text-black":"bg-white text-black"),children:d?e.jsxs(e.Fragment,{children:[e.jsx(L,{className:"w-3 h-3 mr-1"})," Pause"]}):e.jsxs(e.Fragment,{children:[e.jsx(I,{className:"w-3 h-3 mr-1"})," Auto"]})}),e.jsxs(u,{onClick:N,disabled:p||d,className:"bg-[#bd93f9] text-black font-black uppercase text-[9px] h-8 px-4 border-none hover:bg-white transition-all",children:[e.jsx(_,{className:"w-3 h-3 mr-1"})," Step"]})]})]}),e.jsxs("div",{className:"p-6 md:p-8 flex flex-col md:flex-row gap-8 items-center justify-between min-h-[420px]",children:[e.jsxs("div",{className:"flex-1 w-full max-w-lg flex flex-col justify-start space-y-8 shrink-0",children:[e.jsxs("div",{className:"flex flex-col space-y-1",children:[e.jsx("span",{className:"text-[9px] font-black text-[#50fa7b] uppercase tracking-widest pl-2",children:"L1 Input List"}),e.jsxs("div",{className:"flex items-center gap-2 bg-[#0c0f16] border border-[#30363d]/50 p-3 rounded-lg relative",children:[e.jsxs("div",{className:"flex flex-col items-center",children:[e.jsx("div",{className:l("w-10 h-10 flex border items-center justify-center font-black rounded-lg text-lg transition-all duration-300",t.l1Id==="l1_1"?"border-[#50fa7b] bg-[#50fa7b]/10 text-[#50fa7b]":t.stepIndex>=2?"opacity-35 border-[#30363d]":"border-[#30363d]"),children:"1"}),t.l1Id==="l1_1"&&e.jsx("span",{className:"text-[8px] font-black text-[#50fa7b] mt-1",children:"l1"})]}),e.jsx(a,{className:"w-4 h-4 text-[#30363d] opacity-50"}),e.jsxs("div",{className:"flex flex-col items-center",children:[e.jsx("div",{className:l("w-10 h-10 flex border items-center justify-center font-black rounded-lg text-lg transition-all duration-300",t.l1Id==="l1_3"?"border-[#50fa7b] bg-[#50fa7b]/10 text-[#50fa7b]":t.stepIndex>=6?"opacity-35 border-[#30363d]":"border-[#30363d]"),children:"3"}),t.l1Id==="l1_3"&&e.jsx("span",{className:"text-[8px] font-black text-[#50fa7b] mt-1",children:"l1"})]}),e.jsx(a,{className:"w-4 h-4 text-[#30363d] opacity-50"}),e.jsx("div",{className:"text-xs text-[#484f58] uppercase font-bold",children:"NULL"})]})]}),e.jsxs("div",{className:"flex flex-col space-y-1",children:[e.jsx("span",{className:"text-[9px] font-black text-[#ffb86c] uppercase tracking-widest pl-2",children:"L2 Input List"}),e.jsxs("div",{className:"flex items-center gap-2 bg-[#0c0f16] border border-[#30363d]/50 p-3 rounded-lg",children:[e.jsxs("div",{className:"flex flex-col items-center",children:[e.jsx("div",{className:l("w-10 h-10 flex border items-center justify-center font-black rounded-lg text-lg transition-all duration-300",t.l2Id==="l2_2"?"border-[#ffb86c] bg-[#ffb86c]/10 text-[#ffb86c]":t.stepIndex>=4?"opacity-35 border-[#30363d]":"border-[#30363d]"),children:"2"}),t.l2Id==="l2_2"&&e.jsx("span",{className:"text-[8px] font-black text-[#ffb86c] mt-1",children:"l2"})]}),e.jsx(a,{className:"w-4 h-4 text-[#30363d] opacity-50"}),e.jsxs("div",{className:"flex flex-col items-center",children:[e.jsx("div",{className:l("w-10 h-10 flex border items-center justify-center font-black rounded-lg text-lg transition-all duration-300",t.l2Id==="l2_4"?"border-[#ffb86c] bg-[#ffb86c]/10 text-[#ffb86c]":t.stepIndex>=8?"opacity-35 border-[#30363d]":"border-[#30363d]"),children:"4"}),t.l2Id==="l2_4"&&e.jsx("span",{className:"text-[8px] font-black text-[#ffb86c] mt-1",children:"l2"})]}),e.jsx(a,{className:"w-4 h-4 text-[#30363d] opacity-50"}),e.jsx("div",{className:"text-xs text-[#484f58] uppercase font-bold",children:"NULL"})]})]}),e.jsxs("div",{className:"flex flex-col space-y-2",children:[e.jsx("span",{className:"text-[9px] font-black text-[#8be9fd] uppercase tracking-widest pl-2",children:"Merged list state (Dummy + Mutated Connections)"}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 bg-[#0d1117] border border-[#30363d] p-4 rounded-xl relative overflow-hidden min-h-[80px]",children:[t.mergedList.map((s,i)=>{const b=w[s],f=t.currId===s;return e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"flex flex-col items-center",children:[e.jsx("div",{className:l("px-3 py-2 border font-black text-xs rounded transition-all duration-300",b.color,f?"bg-[#bd93f9]/15 border-[#bd93f9] shadow-[0_0_15px_rgba(189,147,249,0.3)] scale-105":"bg-[#0b0e14]"),children:b.val}),f&&e.jsx("span",{className:"text-[8px] font-black text-[#bd93f9] mt-1",children:"curr"})]}),i<t.mergedList.length-1&&e.jsx(a,{className:"w-3.5 h-3.5 text-[#bd93f9]/70 shrink-0"})]},s)}),t.action==="done"&&e.jsxs(e.Fragment,{children:[e.jsx(a,{className:"w-3.5 h-3.5 text-[#bd93f9]/70 shrink-0"}),e.jsx("div",{className:"text-xs text-[#484f58] uppercase font-bold",children:"NULL"})]})]})]})]}),e.jsxs("div",{className:"flex-1 w-full max-w-xs space-y-4",children:[e.jsxs("div",{className:"bg-[#0d1117] border border-[#30363d] rounded-xl p-5",children:[e.jsxs("div",{className:"text-[10px] font-black text-[#8be9fd] uppercase tracking-widest mb-3 flex items-center gap-2",children:[e.jsx(S,{className:"w-4 h-4"})," Sentinel Logic"]}),e.jsxs("p",{className:"text-xs text-[#8b949e] leading-relaxed mb-3",children:["The dummy node remains stationary at index 0. The ",e.jsx("code",{children:"curr"})," pointer updates links iteratively."]}),e.jsxs("div",{className:"text-[10px] font-mono text-[#c9d1d9] bg-black/40 p-2.5 rounded space-y-1",children:[e.jsx("div",{children:"• head = dummy.next"}),e.jsx("div",{children:"• curr.next = chosen node"}),e.jsx("div",{children:"• curr = curr.next"})]})]}),e.jsxs("div",{className:l("p-5 rounded-xl border transition-all duration-300 min-h-[160px]",t.action==="done"?"border-[#50fa7b]/40 bg-[#50fa7b]/5":t.action==="link"?"border-[#bd93f9]/40 bg-[#bd93f9]/5":"border-[#30363d] bg-white/5"),children:[e.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[t.action==="done"?e.jsx(T,{className:"w-4 h-4 text-[#50fa7b]"}):e.jsx(E,{className:"w-4 h-4 text-[#bd93f9]"}),e.jsx("div",{className:"text-[10px] font-black uppercase tracking-widest text-[#c9d1d9]",children:"Execution Trace"})]}),e.jsx("p",{className:"text-xs text-[#c9d1d9] leading-relaxed font-mono mt-3",children:t.reasoning})]})]})]})]})},G=()=>e.jsx(M,{title:"DUMMY NODE MUTATION",badges:[{text:"DSA.LINKEDLIST",color:"text-[#50fa7b] border-[#50fa7b]"},{text:"SENTINEL_NODE",color:"text-[#bd93f9] border-[#bd93f9]"},{text:"O(1) EDGE_CASES",color:"text-[#8be9fd] border-[#8be9fd]"}],children:e.jsx("div",{className:"w-full",children:e.jsxs("main",{className:"space-y-16 md:space-y-32 py-12",children:[e.jsxs("section",{id:"problem",className:"scroll-mt-32",children:[e.jsx("div",{className:"text-[#30363d] font-black text-3xl sm:text-4xl md:text-6xl mb-8 opacity-20 uppercase tracking-tighter",children:"Phase_01"}),e.jsx("h2",{className:"text-3xl font-black text-white mb-8 tracking-wider up
1percase",children:"The Head-Mutation Nightmare"}),e.jsxs("div",{className:"space-y-8 text-[#8b949e] leading-relaxed text-lg",children:[e.jsx("p",{children:"When modifying linked lists, the most common source of bugs is **modifying the head node**. Operations like inserting, deleting, or merging lists behave differently depending on whether the change occurs at the head or in the middle."}),e.jsxs("div",{className:"p-4 md:p-8 border-l-4 border-[#ffb86c] bg-[#ffb86c]/5 rounded-r-lg",children:[e.jsx("div",{className:"text-[10px] font-black text-[#ffb86c] uppercase tracking-widest mb-2",children:"Edge Case Overload"}),e.jsx("h3",{className:"text-xl font-bold text-white mb-4 italic",children:'"Null checks and separate head pointers."'}),e.jsx("p",{className:"text-sm text-[#8b949e] leading-relaxed",children:"Without a dummy node, writing a simple list merge requires checking if the head is null, initializing a new head pointer separately, and writing branch logic for every sub-step. This results in verbose, error-prone code that is hard to read and debug."})]})]})]}),e.jsxs("section",{id:"insight",className:"scroll-mt-32",children:[e.jsx("div",{className:"text-[#30363d] font-black text-3xl sm:text-4xl md:text-6xl mb-8 opacity-20 uppercase tracking-tighter",children:"Phase_02"}),e.jsx("h2",{className:"text-3xl font-black text-white mb-8 tracking-wider uppercase",children:"The Sentinel Anchor"}),e.jsxs("div",{className:"space-y-8 text-[#8b949e] leading-relaxed text-lg",children:[e.jsx("p",{children:"A **Dummy Node** (also known as a sentinel node) is a temporary helper node prepended to the head of a linked list. It contains a placeholder value and serves as a permanent anchor."}),e.jsxs("div",{className:"bg-[#0d1117] border border-[#bd93f9]/30 rounded-2xl p-6 md:p-10 text-center relative overflow-hidden group",children:[e.jsx("div",{className:"absolute inset-0 bg-gradient-to-br from-[#bd93f9]/5 to-transparent opacity-0 group-hover:opacity-100 transition-opacity"}),e.jsx("div",{className:"text-xl md:text-3xl font-black text-white italic mb-6 relative uppercase font-mono tracking-tighter leading-tight",children:"LIST_HEAD = DUMMY.NEXT"}),e.jsxs("p",{className:"text-sm text-[#8b949e] max-w-lg mx-auto relative leading-relaxed",children:["By having a permanent placeholder node at index 0, we can treat all list operations (insertions, removals, merges) uniformly. The actual list head is always stored at ",e.jsx("code",{children:"dummy.next"}),", letting us mutate links without maintaining separate head-assignment logic."]})]}),e.jsx(R,{title:"A Shopping Cart Handle",icon:C,children:"Imagine building a train row-by-row. If you have to push the very first carriage, you have nothing to pull it with. A dummy node is like a handle attached to the front of the cart. You can attach carriages to the handle one-by-one. When the train is assembled, you simply detach the handle and let the first carriage roll out."})]})]}),e.jsxs("section",{id:"visualizer",className:"scroll-mt-32",children:[e.jsx("div",{className:"text-[#30363d] font-black text-3xl sm:text-4xl md:text-6xl mb-8 opacity-20 uppercase tracking-tighter",children:"Phase_03"}),e.jsx("h2",{className:"text-3xl font-black text-white mb-8 tracking-wider uppercase",children:"See It In Action"}),e.jsx("div",{className:"space-y-6 text-[#8b949e] mb-12 text-lg leading-relaxed",children:e.jsxs("p",{children:["Watch the Sentinel Dummy Node (value 0) sit at the front of our merged list. Observe how the ",e.jsx("code",{children:"curr"})," pointer updates links node-by-node. When completed, ",e.jsx("code",{children:"dummy.next"})," points directly to the head of the sorted list."]})}),e.jsx(F,{})]}),e.jsxs("section",{id:"code",className:"scroll-mt-32",children:[e.jsx("div",{className:"text-[#30363d] font-black text-3xl sm:text-4xl md:text-6xl mb-8 opacity-20 uppercase tracking-tighter",children:"Phase_04"}),e.jsx("h2",{className:"text-3xl font-black text-white mb-8 tracking-wider uppercase",children:"The Architecture Boilerplate"}),e.jsxs("div",{className:"space-y-8 text-[#8b949e] leading-relaxed text-lg",children:[e.jsx("p",{children:"Here is the code structure for merging two sorted lists using a dummy node."}),e.jsx(U,{title:"Dummy Node List Merge",complexity:"O(N + M) TIME | O(1) SPACE",code:e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-[#484f58]",children:"// Initialize dummy sentinel"}),e.jsx("br",{}),"dummy = ListNode(0)",e.jsx("br",{}),"curr = dummy",e.jsx("br",{}),e.jsx("br",{}),e.jsx("span",{className:"text-[#bd93f9]",children:"WHILE"})," list1 ",e.jsx("span",{className:"text-[#bd93f9]",children:"AND"})," list2:",e.jsx("br",{}),"  ",e.jsx("span",{className:"text-[#bd93f9]",children:"IF"})," list1.val < list2.val:",e.jsx("br",{}),"    curr.next = list1, list1 = list1.next",e.jsx("br",{}),"  ",e.jsx("span",{className:"text-[#bd93f9]",children:"ELSE"}),":",e.jsx("br",{}),"    curr.next = list2, list2 = list2.next",e.jsx("br",{}),"  curr = curr.next",e.jsx("br",{}),e.jsx("br",{}),e.jsx("span",{className:"text-[#484f58]",children:"// Link remaining elements"}),e.jsx("br",{}),"curr.next = list1 ",e.jsx("span",{className:"text-[#bd93f9]",children:"IF"})," list1 ",e.jsx("span",{className:"text-[#bd93f9]",children:"ELSE"})," list2",e.jsx("br",{}),e.jsx("span",{className:"text-[#bd93f9]",children:"RETURN"})," dummy.next"]})}),e.jsx(W,{codes:{python:`class Solution:
2    def mergeTwoLists(self, list1: Optional[ListNode], list2: Optional[ListNode]) -> Optional[ListNode]:
3        # Create sentinel dummy node
4        dummy = ListNode(0)
5        curr = dummy
6        
7        while list1 and list2:
8            if list1.val < list2.val:
9                curr.next = list1
10                list1 = list1.next
11            else:
12                curr.next = list2
13                list2 = list2.next
14            curr = curr.next
15            
16        # Append remaining nodes
17        curr.next = list1 if list1 else list2
18        
19        # Head of the merged list is dummy.next
20        return dummy.next`,java:`class Solution {
21    public ListNode mergeTwoLists(ListNode list1, ListNode list2) {
22        // Create sentinel dummy node
23        ListNode dummy = new ListNode(0);
24        ListNode curr = dummy;
25        
26        while (list1 != null && list2 != null) {
27            if (list1.val < list2.val) {
28                curr.next = list1;
29                list1 = list1.next;
30            } else {
31                curr.next = list2;
32                list2 = list2.next;
33            }
34            curr = curr.next;
35        }
36        
37        // Append remaining nodes
38        curr.next = (list1 != null) ? list1 : list2;
39        
40        return dummy.next;
41    }
42}`,cpp:`class Solution {
43public:
44    ListNode* mergeTwoLists(ListNode* list1, ListNode* list2) {
45        // Create sentinel dummy node on stack or heap
46        ListNode dummy(0);
47        ListNode* curr = &dummy;
48        
49        while (list1 && list2) {
50            if (list1->
50val < list2->val) {
51                curr->next = list1;
52                list1 = list1->next;
53            } else {
54                curr->next = list2;
55                list2 = list2->next;
56            }
57            curr = curr->next;
58        }
59        
60        // Append remaining nodes
61        curr->next = list1 ? list1 : list2;
62        
63        return dummy.next;
64    }
65};`}})]})]}),e.jsxs("section",{id:"traps",className:"scroll-mt-32",children:[e.jsx("div",{className:"text-[#30363d] font-black text-3xl sm:text-4xl md:text-6xl mb-8 opacity-20 uppercase tracking-tighter",children:"Phase_05"}),e.jsx("h2",{className:"text-3xl font-black text-white mb-8 tracking-wider uppercase",children:"Sentinel Pitfalls"}),e.jsxs("div",{className:"space-y-10",children:[e.jsxs("div",{className:"space-y-4",children:[e.jsxs("h3",{className:"text-lg font-bold text-white uppercase tracking-widest flex items-center gap-3",children:[e.jsx(g,{className:"w-5 h-5 text-[#ff5555]"})," Trap: Returning the Sentinel Node itself"]}),e.jsxs("p",{className:"text-sm text-[#8b949e] leading-relaxed",children:["A common junior developer mistake is returning ",e.jsx("code",{children:"dummy"})," instead of ",e.jsx("code",{children:"dummy.next"}),". This accidentally exposes the sentinel node (often containing value 0 or -1) as the actual head of the returned list, corrupting list data."]}),e.jsx(j,{correct:"return dummy.next // Exclude the sentinel node",wrong:"return dummy // Corrupts the list with the placeholder node"})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("h3",{className:"text-lg font-bold text-white uppercase tracking-widest flex items-center gap-3",children:[e.jsx(g,{className:"w-5 h-5 text-[#ff5555]"})," Trap: Memory Leaking the Heap Dummy Node (C/C++)"]}),e.jsxs("p",{className:"text-sm text-[#8b949e] leading-relaxed",children:["In languages with manual memory management like C or C++, allocating a dummy node on the heap using ",e.jsx("code",{children:"new ListNode(0)"})," and forgetting to ",e.jsx("code",{children:"delete"})," it results in a memory leak."]}),e.jsx(j,{correct:"ListNode* dummy = new ListNode(0);\\n// merge steps...\\nListNode* head = dummy->next;\\ndelete dummy;\\nreturn head;",wrong:"ListNode* dummy = new ListNode(0);\\n// merge steps...\\nreturn dummy->next; // dummy node leaks on heap!"})]})]})]}),e.jsxs("section",{id:"when-to-use",className:"scroll-mt-32",children:[e.jsx("div",{className:"text-[#30363d] font-black text-3xl sm:text-4xl md:text-6xl mb-8 opacity-20 uppercase tracking-tighter",children:"Phase_06"}),e.jsx("h2",{className:"text-3xl font-black text-white mb-8 tracking-wider uppercase",children:"Advanced: Sentinels in DLLs"}),e.jsxs("div",{className:"bg-[#0d1117] border border-[#bd93f9]/30 rounded-lg p-12 relative overflow-hidden mb-12",children:[e.jsx("div",{className:"absolute top-0 left-0 w-full h-2 bg-gradient-to-r from-[#bd93f9] to-[#8be9fd]"}),e.jsx("div",{className:"text-4xl text-[#bd93f9] font-serif italic mb-8",children:'"Can we anchor both head and tail boundaries?"'}),e.jsxs("div",{className:"space-y-6 text-[#8b949e] leading-relaxed text-sm",children:[e.jsxs("p",{children:["Yes! In Doubly Linked Lists (DLLs), we frequently allocate **two** dummy nodes: a ",e.jsx("code",{children:"headSentinel"})," and a ",e.jsx("code",{children:"tailSentinel"}),"."]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4 md:p-8 mt-8",children:[e.jsxs("div",{className:"p-6 bg-black/40 border border-[#30363d] rounded-lg h-full border-t-4 border-t-[#bd93f9]",children:[e.jsxs("span",{className:"text-[#bd93f9] font-bold uppercase tracking-widest text-xs flex items-center gap-2 mb-4",children:[e.jsx(A,{className:"w-4 h-4"})," LRU Cache & Stable DLLs"]}),e.jsxs("p",{className:"text-xs text-[#8b949e] leading-relaxed",children:["In system designs like an LRU Cache, we need to constantly evict from the tail and insert at the head. By keeping a permanent ",e.jsx("code",{children:"headSentinel"})," linked directly to ",e.jsx("code",{children:"tailSentinel"})," initially, insertions and evictions never have to check if the list is empty. We just insert between the sentinels."]})]}),e.jsxs("div",{className:"p-6 bg-black/40 border border-[#30363d] rounded-lg h-full border-t-4 border-t-[#8be9fd]",children:[e.jsxs("span",{className:"text-[#8be9fd] font-bold uppercase tracking-widest text-xs flex items-center gap-2 mb-4",children:[e.jsx(O,{className:"w-4 h-4"})," Loop-Free Operations"]}),e.jsxs("p",{className:"text-xs text-[#8b949e] leading-relaxed",children:["Boundary conditions are entirely absorbed. Every valid node in the DLL is guaranteed to have both a non-null ",e.jsx("code",{children:"prev"})," node and a non-null ",e.jsx("code",{children:"next"})," node, eliminating double-pointer crashes."]})]})]})]})]}),e.jsx(B,{children:'"The cost of a dummy node is a single node allocation in exchange for loop uniformity and elimination of edge cases. In system engineering, sacrificing minor space to enforce clean, exception-free loops is almost always the correct trade-off."'})]}),e.jsx(P,{techniqueId:"dummy-node-mutation"}),e.jsxs("section",{id:"final-takeaway",className:"pb-48 text-center",children:[e.jsx("div",{className:"inline-block px-4 py-1 bg-[#bd93f9]/10 border border-[#bd93f9]/30 text-[#bd93f9] text-[10px] font-black rounded uppercase mb-8 tracking-[0.2em]",children:"MISSION_COMPLETE"}),e.jsxs("h2",{className:"text-4xl md:text-3xl sm:text-4xl md:text-6xl font-black text-white mb-8 tracking-tighter italic",children:['"ANCHOR THE BOUNDARIES. ',e.jsx("br",{}),' UNIFY THE LOOPS."']}),e.jsx("p",{className:"text-[#8b949e] max-w-2xl mx-auto text-lg leading-relaxed mt-4",children:"A single sentinel node avoids special-case head conditions forever."}),e.jsx("div",{className:"mt-24",children:e.jsx(D,{to:"/resources?tab=dsa&subTab=techniques",children:e.jsx("button",{className:"px-16 py-5 bg-white text-black font-black uppercase tracking-widest hover:bg-[#bd93f9] hover:text-white transition-all scale-110 rounded-sm shadow-[0_0_20px_rgba(189,147,249,0.2)
65]",children:"RETURN_TO_LIBRARY"})})})]})]})})});export{G as default};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.