Graph Theory37 sections · 1633 units
Open in Course

Core Idea - Null Pointer Check

(Handling no cycle case)

In a linked list, if there is no cycle, fast will reach null. Check for null before dereferencing. If you do not, you will crash when trying to access null.next. If fast=null\text{fast} = \text{null} or fast.next=null\text{fast.next} = \text{null}, you cannot move fast two steps.

Return null immediately. The list ends, so there is no cycle. This differs from pure functional graphs where every node has a successor. Linked lists can end, functional graphs cannot. Handle this edge case explicitly.