Bird
0
0
DSA Cprogramming~10 mins

Detect Cycle in Linked List Floyd's Algorithm in DSA C - Interactive Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to initialize the slow pointer to the head of the linked list.

DSA C
struct Node* slow = [1];
Drag options to blanks, or click blank then click option'
Aslow
BNULL
Chead
Dfast
Attempts:
3 left
💡 Hint
Common Mistakes
Initializing slow to NULL will cause the loop to never start.
Using fast instead of head confuses the pointers.
2fill in blank
medium

Complete the condition to continue the loop while both fast and fast->next are not NULL.

DSA C
while (fast != NULL && [1] != NULL) {
Drag options to blanks, or click blank then click option'
Aslow->next
Bslow
Chead->next
Dfast->next
Attempts:
3 left
💡 Hint
Common Mistakes
Checking slow->next instead of fast->next causes incorrect loop conditions.
Not checking fast->next leads to segmentation faults.
3fill in blank
hard

Fix the error in moving the fast pointer two steps ahead.

DSA C
fast = [1]->next;
Drag options to blanks, or click blank then click option'
Afast->next
Bslow->next
Cfast
Dhead
Attempts:
3 left
💡 Hint
Common Mistakes
Using slow->next moves the wrong pointer.
Assigning fast to fast without moving causes infinite loop.
4fill in blank
hard

Fill both blanks to correctly move slow and fast pointers inside the loop.

DSA C
slow = slow[1];
fast = fast[2]->next;
Drag options to blanks, or click blank then click option'
A->next
B->prev
Attempts:
3 left
💡 Hint
Common Mistakes
Using ->prev moves backward, which is incorrect for singly linked list.
Moving fast only one step causes incorrect cycle detection.
5fill in blank
hard

Fill all three blanks to complete the cycle detection condition inside the loop.

DSA C
if (slow [1] fast) {
    return [2];
}
slow = slow[3];
Drag options to blanks, or click blank then click option'
A==
B1
C->next
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Using != instead of == misses the cycle detection.
Returning 0 means no cycle, which is wrong here.
Not moving slow pointer causes infinite loop.