Hacker News new | ask | show | jobs
by whatever1 301 days ago
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 ?

2 comments

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.