3

It seems that in python 3 the check time to evaluate:

if x in range(n)

should be O(1), is it? Can you point me to some documentation?

(In 2.7 ranges are lists so there the time complexity is surely linear)

user6794223
  • 121
  • 8
  • I don't know the exact details in how python implement that, but I think this would be linear search, therefore `O(n)` – thuyein May 17 '18 at 02:12
  • 2
    @ThuYeinTun See https://stackoverflow.com/questions/30081275/why-is-1000000000000000-in-range1000000000000001-so-fast-in-python-3, and no it isn't – cs95 May 17 '18 at 02:14
  • @cᴏʟᴅsᴘᴇᴇᴅ Thanks, I just saw the duplicate tag. Reading now. – thuyein May 17 '18 at 02:15

0 Answers0