Mid point traversal

I didn’t get how is it just one traversal if we are doing fast.next and slow.next every time until we reach the end node. And also is this method better than the one which uses size variable?

It’s just a single traversal as we are looping over the elements only once and handling both the slow and fast pointers in the same loop.
Also, a correction: the speed of fast pointer is twice of the speed of slow pointer, so we are using fast=fast.next.next and slow=slow.next

This method is better when the size variable is not provided to us as we can find the answer in just one traversal.

Ok thanks, and one more thing that if we use size variable then we would do getNodeAt(size/2); which I think is also single traversal.

Yes, if we have a size variable being managed in our linkedlist class, we can get the middle node using getNodeAt(size/2) in a single traversal since getNodeAt() uses a single loop to find the element at mentioned position.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.