Open In App
Related Articles

GATE | GATE CS Mock 2018 | Question 30

Improve Article
Save Article
Like Article

Suppose there are two singly linked lists both of which intersect at some point and become a single linked list. The head or start pointers of both the lists are known, but the intersecting node and lengths of lists are not known. What is worst case time complexity of optimal algorithm to find intersecting node from two intersecting linked lists?


Θ(n*m), where m, n are lengths of given lists


Θ(n^2), where m>n and m, n are lengths of given lists


Θ(m+n), where m, n are lengths of given lists


Θ(min(n, m)), where m, n are lengths of given lists

Answer: (C)


This takes Θ(m+n) time and O(1) space in worst case, where M and N are the total length of the linked lists.

  1. Traverse the two linked list to find m and n.
  2. Get back to the heads, then traverse |m − n| nodes on the longer list.
  3. Now walk in lock step and compare the nodes until you found the common ones.

Option (C) is correct.

Quiz of this Question
Please comment below if you find anything wrong in the above post

Last Updated : 03 Jan, 2018
Like Article
Save Article
Similar Reads