Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

N^2 is just two nested loops. It trivially shows up everywhere you have 2D arrays.

Do I really need to make my code spaghetti if the array sizes are small enough to not impact my speed ?



Iterating over a 2D array using nested loops is an O(N) operation. N is the size of your data, how it's represented in an array is irrelevant.


if you can guarantee N is small, then it’s probably not an issue.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: