Is a dynamic array provided by the Standard Template Library (STL).
Vector
Unlike regular arrays, ______ can resize automatically as elements are added or removed.
Vectors
They are stored in contiguous memory and support random access, just like arrays
Vectors
What are the use cases of vectors
Dynamic Arrays
Matrix Representation (2D Arrays)
Graph Representation
Dynamic Data Structures
Sorting and Searching Algorithms
Dynamic Input Handling
Database-like Application
Game Development (Handling Game Objects)
Vectors are often used as a replacement for fixed-size arrays. In cases where the number of elements is not known in advance, vectors allow dynamic resizing.
Dynamic Arrays
Vectors represent matrices or multi-dimensional arrays efficiently. This is useful in applications like image processing, where you may need to store pixel data, or for mathematical computations like matrix multiplication.
Matrix Representation (2D Arrays)
Vectors are frequently used to store graphs, particularly using an adjacency list, Each node in the graph can be a vector containing the nodes it connects to.
Graph Representation
Vectors can act as a flexible stack, queue, or deque (Double-ended queue) in many algorithms
Dynamic Data Structures
Vectors are a common data structure for sorting and searching algorithms due to their random-access capabilities
Sorting and Searching Algorithms
In scenarios where the amount of input data is unknown (e.g., reading from a file, user input), vectors are perfect for storing data dynamically.
Dynamic Input Handling
Vectors can act as in-memory storage for rows of data, where each row is a vector of values. This is useful in simple database-like applications for storing and querying data
Database-like Application
Vectors can store dynamic collections of game objects (like characters, enemies, or projectiles) that are created or destroyed during the game.
Game Development (Handling Game Objects)
Store dynamic student records, scores, or IDs
Student Management System
Store a growing list of selected products
Online Shopping Cart
Maintain a list of enemies, items, or players.
Game Development
Use vector of vectors and adjancency lists
Graph Algorithms
Dynamic Storage for lines or words typed
Text Editor
Maintain a list of recent files accessed
File Systems
What are the common operations
push_back(x)
pop_back()
size()
operator[]
at(index)
empty()
clear()
front and back()
Add to end
push_back(x)
Remove last element
pop_back()
Returns number of elements
size()
Accesses element by index without bounds checking
operator[]
Accesses element by index with bounds checking (throws exception if out of range).
at(index)