Algorithm
Algorithm complexity
1D
2D
Didactic/Better
O(Nn)
O(NMn
2
)
Optimized
O(N + 0.3n)
O(NMn)