I recently started learning about vectors in c++ but I have issues regarding where to utilize them .
Can you suggest some beginner problems which need vectors?
vectors are especially used when number of elements to be stored is unknown unlike array.
vectors can be used for representing a graph in adjacency list (which is the basic to solve all kinds of graph problems which includes dfs, bfs etc.)
1 Like
You can also look into how to use them for hashing when multiple keys fall into the same bucket.
Think of vectors as an array which is of the dynamic type. Basically, the questions from vectors are never asked in particular. But they are used in almost all the problems.
- Graphs/Trees Representation - Adjacency list
- Dynamic array, where size of array is not known.
- Various inbuilt functions, like sort, lower_bound,upper_bound, size, binary_search,pop and many other are easily implementable through vectors.
- Used as hashing, initializing the vector with some specific value and used as hashing.
- Segment tree can also be built using vectors.
As of now, I remember these topics only. Specific problems to learn vectors other than this instead of array start using vectors and then you’ll know the beauty of vectors over arrays.
Hope this helps!
1 Like