Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Is this O(1) or O(n)?
#4
Definitely not constant in the size of your input.

Take just this line:
output = [None] * minum * 2
Do you think that is a constant time operation that is unaffected by the size of your strings?
It isn't.
Your slicing is also not constant time.
Your final join is also not constant time.

Just because you didn't explicitly write a loop doesn't make this constant time.

O(n).
Reply


Messages In This Thread
Is this O(1) or O(n)? - by hshivaraj - Dec-17-2017, 02:36 PM
RE: Is this O(1) or O(n)? - by squenson - Dec-17-2017, 03:54 PM
RE: Is this O(1) or O(n)? - by hshivaraj - Dec-17-2017, 04:23 PM
RE: Is this O(1) or O(n)? - by Mekire - Dec-17-2017, 05:20 PM
RE: Is this O(1) or O(n)? - by hshivaraj - Dec-17-2017, 05:26 PM
RE: Is this O(1) or O(n)? - by wavic - Dec-17-2017, 05:32 PM
RE: Is this O(1) or O(n)? - by micseydel - Dec-17-2017, 08:50 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020