1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[3391],{3391:e=>{e.exports=JSON.parse('{"metadata":{"id":"dsa-basics-basic-linked-lists-circular-linked-list-concepts","name":"Circular Linked List Concepts","category":"Graph","description":"Traverse the circular linked list 4 -> 7 -> 9 -> 4 exactly once, stopping when curr returns to the recorded start node after visiting nodes.","difficulty":"Easy","estimatedTime":"5 minutes","prerequisites":["node-structure-and-pointers","traversal-in-linked-lists","insertion-techniques","deletion-techniques","dummy-and-sentinel-nodes"]},"layout":{"type":"graph","nodes":[{"id":"A","value":4,"x":160,"y":220},{"id":"B","value":7,"x":370,"y":220},{"id":"C","value":9,"x":580,"y":220}],"edges":[{"from":"A","to":"B","directed":true},{"from":"B","to":"C","directed":true},{"from":"C","to":"A","directed":true}],"codeBlocks":[{"id":"dsa-basics-basic-linked-lists-circular-linked-list-concepts-code","language":"pseudo","lines":["if head is null, return an empty output","start = head","curr = start","repeat"," append curr.value to output"," curr = curr.next","until curr equals start","return output"]}],"regions":{"graphPanel":{"position":"left","title":"Circular List"},"codePanel":{"codeBlockId":"dsa-basics-basic-linked-lists-circular-linked-list-concepts-code","position":"right","title":"Pseudocode"}}},"initialState":{"pointers":{"head":{"id":"head","type":"custom","index":0,"nodeId":"A","label":"head","color":"#2563EB"},"start":{"id":"start","type":"start","index":0,"nodeId":"A","label":"start","color":"#7C3AED"},"curr":{"id":"curr","type":"custom","index":0,"nodeId":"A","label":"curr","color":"#EA580C"}},"highlights":[],"flags":{"currInitialized":false,"visitedCount":0,"cycleConfirmed":false,"traversalComplete":false},"annotation":"State 0: head and start refer to [4]. The next link from [9] returns to [4], so the list has no null ending. output = [].","aux":{"output":[]},"uiState":{"activeCodeBlockId":"dsa-basics-basic-linked-lists-circular-linked-list-concepts-code","activeCodeLine":2}},"steps":[{"stepNumber":1,"title":"Record the starting node","description":"Set curr to the recorded start node [4] before beginning the visit loop.","explanation":"The traversal must remember start because a circular list does not end at null. The return edge from [9] to [4] will later identify one completed cycle.","changes":{"flags":{"currInitialized":true},"highlights":{"add":[{"index":0,"type":"current"}],"remove":[],"clear":false},"annotation":"State 0: start = [4] and curr is prepared at [4]. output = []. The closing link [9] -> [4] is not a null link."},"technicalDetails":{"complexity":"Traversal uses O(n) time for n nodes in one cycle and O(1) extra traversal space.","insight":"Use the saved start node as the stopping reference, not null.","warning":"Checking curr != null would never terminate on this circular list."},"highlight":true,"uiState":{"activeCodeBlockId":"dsa-basics-basic-linked-lists-circular-linked-list-concepts-code","activeCodeLine":3}},{"stepNumber":2,"title":"Visit 4 and advance to 7","description":"Process node [4], append 4 to output, then follow its next link so curr moves to [7].","explanation":"State 1: output becomes [4]. After advancing, curr is [7], the next node that has not yet been visited.","changes":{"pointers":{"curr":{"index":1,"nodeId":"B"}},"highlights":{"add":[{"index":0,"type":"visited"},{"index":1,"type":"current"}],"remove":[],"clear":false},"flags":{"visitedCount":1},"aux":{"output":[4]},"annotation":"State 1: [4] was processed; output = [4]. curr advanced along [4] -> [7], so curr = [7]."},"technicalDetails":{"insight":"Invariant: output contains nodes visited before curr in forward order; curr is the next node to visit."},"highlight":true,"uiState":{"activeCodeBlockId":"dsa-basics-basic-linked-lists-circular-linked-list-concepts-code","activeCodeLine":6}},{"stepNumber":3,"title":"Visit 7 and advance to 9","description":"Process node [7], append 7 to output, then move curr through its next link to [9].","explanation":"State 2: output becomes [4, 7]. Nodes [4] and [7] are visited in forward order, while curr now identifies [9] as the next node to visit.","changes":{"pointers":{"curr":{"index":2,"no
1deId":"C"}},"highlights":{"add":[{"index":1,"type":"visited"},{"index":2,"type":"current"}],"remove":[1],"clear":false},"flags":{"visitedCount":2},"aux":{"output":[4,7]},"annotation":"State 2: [7] was processed; output = [4, 7]. curr advanced along [7] -> [9], so curr = [9]."},"technicalDetails":{"insight":"The invariant remains true: output is the forward-order prefix from start up to, but not including, curr."},"highlight":true,"uiState":{"activeCodeBlockId":"dsa-basics-basic-linked-lists-circular-linked-list-concepts-code","activeCodeLine":6}},{"stepNumber":4,"title":"Visit 9 and follow the closing link","description":"Process node [9], append 9 to output, then follow [9].next back to [4].","explanation":"State 3: output becomes [4, 7, 9]. curr returns to [4], which is the recorded start node. This return is expected in a circular list and is not another node to output.","changes":{"pointers":{"curr":{"index":0,"nodeId":"A"}},"highlights":{"add":[{"index":2,"type":"visited"},{"index":0,"type":"comparing"}],"remove":[2],"clear":false},"flags":{"visitedCount":3,"cycleConfirmed":true},"aux":{"output":[4,7,9]},"annotation":"State 3: [9] was processed; output = [4, 7, 9]. Following [9] -> [4] makes curr = start."},"technicalDetails":{"insight":"Termination becomes valid only now: curr has returned to start after one or more visits.","warning":"Do not append [4] again after following the closing edge."},"highlight":true,"uiState":{"activeCodeBlockId":"dsa-basics-basic-linked-lists-circular-linked-list-concepts-code","activeCodeLine":6}},{"stepNumber":5,"title":"Stop after one full cycle","description":"Compare curr with start. Both refer to [4], so stop and return the completed output [4, 7, 9].","explanation":"State 4: curr has returned to start after three visits. The loop stops before visiting [4] again, completing exactly one cycle.","changes":{"highlights":{"add":[{"index":0,"type":"success"}],"remove":[0],"clear":false},"flags":{"traversalComplete":true},"annotation":"State 4: curr = start = [4] after one or more visits. Stop with output = [4, 7, 9]."},"technicalDetails":{"complexity":"Exactly three node visits occur here, one per node in the cycle.","insight":"The stopping rule is curr equals start after a completed visit, not curr equals null.","warning":"A one-node circle also needs one visit before this comparison stops the traversal."},"highlight":true,"uiState":{"activeCodeBlockId":"dsa-basics-basic-linked-lists-circular-linked-list-concepts-code","activeCodeLine":7}}],"conclusion":{"keyTakeaways":["A circular linked list ends by linking its final node back to an earlier node, often head, rather than linking to null.","Record start before traversal and stop only when curr returns to start after at least one visit.","For the example 4 -> 7 -> 9 -> 4, one-cycle traversal produces [4, 7, 9].","During traversal, output contains visited nodes before curr, and curr is the next node to visit."],"commonMistakes":["Using curr != null as the loop condition causes an infinite traversal because a circular list never reaches null.","Using curr != head when curr starts at head visits zero nodes in a one-node circle.","Treating head.next = head as empty skips a valid one-node circular list; only head = null represents an empty list."],"nextSteps":["Trace a one-node circular list where head points to a node containing 5 and that node points back to itself.","Implement insertion and deletion while preserving the closing link to the start node.","Compare one-cycle traversal with traversal that intentionally performs a fixed number of cycles."],"practiceProblems":[]}}')}}]);
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.