4 ms·
This suggests runtime complexity will be O(n^2), which is rarely an optimal solution to a problem.
by SauciestGNU 4y ago
This suggests runtime complexity will be O(n^2), which is rarely an optimal solution to a problem.
- comex 4y agoPerhaps, but “nested loops” by itself is an odd way to describe that.
- jackblemming 4y agoUnless they verify the source code of every library they use and verify the entire call stack; it probably has a nested for loop somewhere. Good thing computers are fast!
- silvertaza 4y agoDepending on n, oftentimes nested loops are more readable and maintainable than the optimal solution. Of course too many levels of nesting is inherently a code smell that indicates other issues.
- strikelaserclaw 4y agothat says nothing if you don't know the size of the input and the problem at hand. Sometimes the best you can do is N^2.
- sicp-enjoyer 4y agoSome common cases (that wouldn't be considered algorithms) are: - working with grids (rows and columns) - iterating over nested data structures (eg. all people in a group).