Python algorithm analysis What is the big o for this algorit

Python algorithm analysis

What is the big (o) for this algorithm:

l = [\"hi\", \"bye\"]

l2 = [\"bye2\", \"hi2\"]

l1 == l2

I think it is O(N^2). Please justify.

Solution

Its O(N)

Explanation: Equality in ordered set is always a linear operation. LIst is a ordered type of data structure, where order matter hence [1,2] is not equal to [2,1] hence for equality only linear check is required. More precisely the complexity is O(x) where x = min(N,M) {N and M are no. of elements in list1 and list2}

You can check on https://www.ics.uci.edu/~pattis/ICS-33/lectures/complexitypython.txt about complexity of various operations in python

Python algorithm analysis What is the big (o) for this algorithm: l = [\

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site