Time complexity question | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
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 Respostas
+ 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