Time complexity question | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
0

Time complexity question

Is anyone able to help with the TC of the following operation. Assume that BI and CI are the same length as C: for i in range(0, len(C)):         if BI[i]==0 and CI[i]>=1:             return True

19th Dec 2020, 1:49 PM
438bebop
2 Antworten
+ 1
I haven’t done time complexity in awhile, but linear iteration is O(n). I’m also assuming that Bl and Cl are simply arrays and therefore have random access. Range() probably takes O(n) and I’ve heard that len() is O(1) since Python automatically stores the length of iterable data structures. So, to sum up, I’d say it would resemble linear time: O(n).
20th Dec 2020, 2:41 AM
Oceanlight
Oceanlight - avatar
+ 1
Thanks, I appreciate that
20th Dec 2020, 10:37 AM
438bebop