What is the difference between a Vector and an Array. Discuss the advantages and disadvantages of both?



Differences between a Vector and an Array

- A vector is a dynamic array, whose size can be increased, where as an array size can not be changed.
- Reserve space can be given for vector, where as for arrays can not.
- A vector is a class where as an array is not.
- Vectors can store any type of objects, where as an array can store only homogeneous values.

Advantages of Arrays:
- Arrays supports efficient random access to the members.
- It is easy to sort an array.
- They are more appropriate for storing fixed number of elements

Disadvantages of Arrays:
- Elements can not be deleted
- Dynamic creation of arrays is not possible
- Multiple data types can not be stored

Advantages of Vector:
- Size of the vector can be changed
- Multiple objects can be stored
- Elements can be deleted from a vector

Disadvantages of Vector:
- A vector is an object, memory consumption is more.

 if any doubts or queries please comment ðŸ™‚

Comments

Popular posts from this blog

Python and C++ program to implement multiplication of 2d array (Matrix multiplication)

How to find and replace a node in Linked List

What is AI (Artificial Intelligence )? and its characteristics