Question

I have a question about calculating time-complexity in algorithms. Is it possible to have a notation such as O(n^4) if you have four nested for-loops?

Était-ce utile?

La solution

Quite simply, the answer is yes. Four nested loops could (depending on the loops) be O(n4).

There are not a lot of polynomial-time algorithms with complexity above cubic, but they do exist. For example, the well-known AKS primality test is O(k12) in its original formulation (where k is the length of the input number), though it has been recently reduced to k7.5.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top