424 views
3 votes
3 votes

Here ans given option(C) but i think option(b) is better why bez if in a linked list loop if exits then slower pointer(p) and faster pointer(q) has no NULL value at any situation.but if a loop is not present in linked list then faster pointer(q) first reach the NULL value.so in option(C) we are check p!=NULL one more condition unnecessary which is not required.

If I am wrong Plz correct me Arjun Suresh sir............

1 Answer

0 votes
0 votes

I think answer will be C
 look in b) q!=null it is ok

but p can be null as nothing is mentioned about p

now if p=head=null how can you run head->next i.e. Q to detect a loop

so to successful completion of the loop(program in this case) both P and Q have to be NOT NULL

so C) is the correct answer from my point of view here.

No related questions found