vector & pair : Introduction, Use, Example, Implementation, question

 Vectors and pairs 

Vectors

vectors


Introduction :

Vector is an advanced form of an array or can say it is the resolution of drawbacks of arrays while we use it 
, if we talk about a definition so; a Vector is a form of an array with a special functionality in this we don't want to pre-define the size of the Vectors, but in the case of the array we need to define the size of this feature makes a vector Dynamic type

Vector Definition or what is a vector, answer: A vector is the type of array that automatically define its size along with use or in run time

Use :

We use vectors when there is no proper surety of the size of the Array

Example :

if we want to make a dynamic array that automatically states its size ;

#include <iostream>
#include <vector>
int main(){
          vector<int> v;           //here v is int type data storing vector 
          v[0]=433;
          v[1]=43;                   // NOTE: We do not define the size of it
          cout<<v[1]<<" "; 
                                         O/P = 433
}
if we talk about vector v then it has a size of 2 but if we also add v[2] then the size becomes 4 rather than 3 because the size of the vector dynamically increased in the powers of 2 when it tries to extend the current size of vectors

*This is called 2 power dynamisation of vector

Implementation :

To implement it we need to know about the syntax and basic things about vector

* We use the vectors because of the Dynamic automation 
* Vectors themselves can change their size many times
* Vectors can be string, bool, int etc. 
* Vectors Dynamic characters make a little latency in the speed of implementation
* To prevent heavy time use we accept vector with its power 2 dynamisation technique
* SYNTAX 
    vector</Data Type/> /Name of vector/

integer type vector 
    vector<int> vec;
//
here the vec is the vector for data type integers  


Question :

let's try a question from GeeksForGeeks 
Go there and visit to practice and search for arrays and search for vectors problem 

Comments

Pageviews