Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Complexity

Name: Anonymous 2012-11-12 16:01

If a recursive algorithm calls itself twice for each element in a set, does that mean it has n^2 complexity, or is that 2n and therefore n complexity? I am confused.

Name: Anonymous 2012-11-12 17:12

Depends how the size of the set the algorithm works on reduces every time it calls itself.
The simplest case of O(n2) that I can think of is for (i in set) { for (j in set) { do a thing } }, but that's not recursive.

Is there any recursive O(n2) algorithm? On a minute of thinking, I don't see how there could be one that isn't on the logarithmic scale.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List