What is the time complexity of the given python code?
As there is single loop, I think its O(n) but there are two if loops too for element search from two different lists at the same time.
def disjoint(A,B,C):
for ele in A:
if ele in B and ele in C:
return print('Common element found and it is {}'.format(ele))
break
else:
return print('sets are disjoints')
A=[1,2,5,4,11]
B=[5,6,7,8,9]
C=[5,6,7,8,9]
disjoint(A,B,C)
Aucun commentaire:
Enregistrer un commentaire