Hacker News new | past | comments | ask | show | jobs | submit login

> proposes a vector of vectors to make a 2D matrix

what would be the right way to do this?




2D arrays that are laid out as a linear array of mn elements are faster to iterate through. That's what happens when you declare e.g. int a[5][4], you get the same layout as int a[20]. A vector of vectors is fairly sprawling in memory, and generally matrices don't get resized so you want this compact form because it's quicker to loop through (either way is O(mn), but one has a way better coefficient).




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

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

Search: