Traverse the 2 linked lists. Check if the node just before NULL is the
same in both the linked lists. If it is then there is an
intersection(return 1), otherwise not (return 0). The logic is that
whenever 2 linked lists intersect, all the nodes starting from the
point of intersection to the end of the linked lists are the same.

Time Complexity:O(m+n),where m & n are the size of the 2 linked lists
Space Complexity : O(1)

Ankit Sambyal
BITS Pilani



On Thu, Jun 2, 2011 at 11:54 AM, ross <[email protected]> wrote:
>
> Given 2 linked lists, determine whether they intersect or not?
> (question is not find the point of intersection, which i am sure can
> be done by computing the lengths of both lists (len1 and len2)
> and traversing the larger list by |len1 - len2| and traversing
> subsequently
> until 2 ptrs meet.
>
> I am looking for a bettre approach that does not find the intersection
> pt
> but whether that the lists intersect or not"
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Algorithm Geeks" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> For more options, visit this group at 
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to