The Gateway to Computer Science Excellence
+2 votes
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*}$
in Algorithms by Active (1.8k points)
edited by | 251 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

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

Related questions

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
50,833 questions
57,747 answers
108,089 users