139 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*}
edited | 139 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)

O(m+n) similar to combine step of merge sort.
selected by
+1 vote
Max(m,n)