Python Forum
Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Efficiency Crash Course
#2
Mekire: Re-adding some good discussion we had on the original thread.

Very nice.  I wouldn't mind a follow up tutorial that went into more depth on the common time complexities encountered. I still, for instance, find correctly identifying O(nlogn) to be tricky.

On the point of your example, using string concatenation does, as you alluded to, sometimes make it hard to see these results in the wild.  You could go into more detail with it here, but I think perhaps this past thread might suffice:
Time complexity different between operating systems. Why?

I tend to use examples with the list.count() builtin vs dictionary counting (or using collections.Counter) to illustrate the quadratic vs linear time of counting items in a large sequence. 

I for instance have often seen people do things like this (and think themselves very clever):
count_items = {item:items.count(item) for item in items}
Not realizing that this is O(n^2).

Whereas the less intuitive:
count_items = {}
for item in items:
    count_items[item] = count_items.get(item, 0)+1
performs in O(n).

-Mek


Messages In This Thread
Efficiency Crash Course - by micseydel - Oct-10-2016, 03:37 PM
RE: Efficiency Crash Course - by Mekire - Jan-18-2017, 09:21 PM
RE: Efficiency Crash Course - by micseydel - Jan-18-2017, 09:23 PM

Forum Jump:

User Panel Messages

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