GATE CSE
First time here? Checkout the FAQ!
x
+2 votes
159 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.1k points)  
edited by | 159 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 (47k points)  
selected by
+1 vote
Max(m,n)
answered by Veteran (15k points)  
that will be the best case i think:max(m,n)
yes, it should be m+n. Editing.


Top Users May 2017
  1. akash.dinkar12

    3302 Points

  2. pawan kumarln

    1776 Points

  3. Bikram

    1646 Points

  4. sh!va

    1640 Points

  5. Arjun

    1396 Points

  6. Devshree Dubey

    1272 Points

  7. Debashish Deka

    1142 Points

  8. Angkit

    1044 Points

  9. LeenSharma

    1000 Points

  10. Arunav Khare

    754 Points

Monthly Topper: Rs. 500 gift card
Top Users 2017 May 22 - 28
  1. Bikram

    732 Points

  2. Arnab Bhadra

    402 Points

  3. pawan kumarln

    402 Points

  4. bharti

    304 Points

  5. LeenSharma

    238 Points


22,823 questions
29,142 answers
65,209 comments
27,666 users