GATE CSE
First time here? Checkout the FAQ!
x
+2 votes
169 views
Two linked lists having n and m elements are stored in sorted order. What is the worst case complexity of program to print common elements of two lists ?

$\begin{align*} &A. \ \ O(n) \\ &B. \ \ \text{max}(m,n) \\ &C. \ \ \text{min}(m,n) \\ &D. \ \ m+n \end{align*}$
asked in Algorithms by Active (1.9k points)  
edited by | 169 views

As in worst case may be we ended up by comparing every element of both the list in alternate manner hence , it would be O(m+n)

2 Answers

+4 votes
Best answer
O(m+n) similar to combine step of merge sort.
answered by Veteran (50.5k points)  
selected by
+1 vote
Max(m,n)
answered by Veteran (15.2k points)  
that will be the best case i think:max(m,n)
yes, it should be m+n. Editing.


Top Users Jul 2017
  1. Bikram

    4062 Points

  2. manu00x

    2464 Points

  3. Debashish Deka

    1850 Points

  4. joshi_nitish

    1658 Points

  5. Arjun

    1294 Points

  6. Hemant Parihar

    1184 Points

  7. Arnab Bhadra

    1112 Points

  8. Shubhanshu

    1054 Points

  9. Ahwan

    900 Points

  10. rahul sharma 5

    706 Points


24,022 questions
30,966 answers
70,346 comments
29,342 users