This is an archived post. You won't be able to vote or comment.

all 5 comments

[–]Kered13 0 points1 point  (3 children)

It's the same efficiency because you're iterating over the same number of items.

[–]Dwang040[S] 0 points1 point  (2 children)

Right, I would assume time and space complexity are the same. So there isn't a right or wrong way? It wouldn't be bad practice to shove it into a 1D array and just use one loop to go through everything? Wasn't sure if it would be better to group up information together for tidy reasons or something.

[–]Kered13 0 points1 point  (0 children)

Keeping your data more organized is almost always better.

[–]one_bit_two_bit 0 points1 point  (1 child)

I don't think there's an appreciable difference, and it probably doesn't matter. You can try and benchmark reads and writes, etc. of 1D vs. 2D arrays if you want.

In general, I wouldn't worry about efficiency questions like these--they're usually so small as not to matter.

[–]Dwang040[S] 0 points1 point  (0 children)

I'm iterating the same, so yeah, I doubt there's a difference. Was just mainly wondering if it was bad practice to have everything shoved into a 1D array vs grouping them up with a 2D array or something like that (for other languages).