In this article we will understand which is better – vector<vector<int>> or vector<pair<int, int>>.
- vector has dynamic size so end up using heap but pair is fixed so there is no overhead.
- Pair has better cache locality and fewer indirections.
- Dynamic memory allocation is slow so vector memory allocation is slow.
- Pairs have consecutive memory allocations which is faster to access for modern computer systems, while vectors may have distributed memory location.
This concludes that pair<int, int> is better choice than vector<int>