Time complexity of accessing a Python dict

I am writing a simple Python program. My program seems to suffer from linear access to dictionaries, its run-time grows exponentially even though the algorithm is quadratic. I use a dictionary to memoize values. That seems to be a bottleneck. The values I’m hashing are tuples of points. Each point is: (x,y), 0 <= x,y … Read more

Which is better: O(n log n) or O(n^2)

Okay so I have this project I have to do, but I just don’t understand it. The thing is, I have 2 algorithms. O(n^2) and O(n*log2n). Anyway, I find out in the project info that if n<100, then O(n^2) is more efficient, but if n>=100, then O(n*log2n) is more efficient. I’m suppose to demonstrate with … Read more

What is the meaning of O( polylog(n) )? In particular, how is polylog(n) defined?

Brief: When academic (computer science) papers say “O(polylog(n))”, what do they mean? I’m not confused by the “Big-Oh” notation, which I’m very familiar with, but rather by the function polylog(n). They’re not talking about the complex analysis function Lis(Z) I think. Or are they? Something totally different maybe? More detail: Mostly for personal interest, I’ve … Read more

why does accessing an element in an array take constant time?

Lets say I have an array as: int a[]={4,5,7,10,2,3,6} when I access an element, such as a[3], what does actually happen behind the scenes? Why do many algorithm books (such as the Cormen book…) say that it takes a constant time? (I’m just a noob in low-level programming so I would like to learn more … Read more

Sorting algorithms for data of known statistical distribution?

It just occurred to me, if you know something about the distribution (in the statistical sense) of the data to sort, the performance of a sorting algorithm might benefit if you take that information into account. So my question is, are there any sorting algorithms that take into account that kind of information? How good … Read more

What’s the Time Complexity of Average Regex algorithms?

I’m not new to using regular expressions, and I understand the basic theory they’re based on–finite state machines. I’m not so good at algorithmic analysis though and don’t understand how a regex compares to say, a basic linear search. I’m asking because on the surface it seems like a linear array search. (If the regex … Read more

Is list::size() really O(n)?

Recently, I noticed some people mentioning that std::list::size() has a linear complexity. According to some sources, this is in fact implementation dependent as the standard doesn’t say what the complexity has to be. The comment in this blog entry says: Actually, it depends on which STL you are using. Microsoft Visual Studio V6 implements size() … Read more

es6 Map and Set complexity, v8 implementation

Is it a fair assumption that in v8 implementation retrieval / lookup is O(1)? (I know that the standard doesn’t guarantee that) Answer Is it a fair assumption that in v8 implementation retrieval / lookup is O(1)? Yes. V8 uses a variant of hash tables that generally have O(1) complexity for these operations. For details, … Read more