Master programming syntax, solve interactive challenges & run live code in Syntaxis Explore Arena →
menu_book Course Curriculum (Data Structures & Algorithms) expand_more
Complexity & Foundations
Arrays & Strings
Linked Lists
Stacks & Queues
Hashing
Trees & Heaps
Graphs
Sorting Searching & DP

Detect cycle

Learn Detect cycle in Data Structures & Algorithms with a focused explanation, a topic-specific example, edge guidance, and a mastery check.

12 min read • Beginner
data-structures-algorithms-026.py
python
class Node:
    def __init__(self,v): self.v,self.next=v,None
a,b,c=Node("a"),Node("b"),Node("c"); a.next=b;b.next=c;c.next=b
slow=fast=a
while fast and fast.next:
    slow,fast=slow.next,fast.next.next
    if slow is fast: print("cycle"); break
What to watch
Content source & attribution
Original Syntaxis Content · Original Syntaxis Content