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

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
Max(m,n)
by Boss (18.5k points)
0
that will be the best case i think:max(m,n)
0
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
199,474 comments
108,089 users