

Adding elements to the end of vector is far more efficient. Because Vector's are array-like, then every time you want to add element to the beginning of the vector all the array has to be copied. You can add new data to the end and to the front of the vector. There are various methods vectors such as begin(). In case of array, it would cause an error. You can further optimize it, so vector will be 1 1/2 of it's size.
#Use of basic data structures full#
Now, when the array is full and you try to add a new element, the vector will double it's size and allocate a new memory of size 10. When you define the size of the vector, for example 5. It's an array with dynamically allocated space, every time you exceed this space new place in memory is allocated and old array is copied to the new one.

Ī can be used to access a particular location of an array. Their elements are located in contiguous locations in memory,Ĭredits: int a //declares an array of size 10. Memory is allocated immediately after the array is created and it’s empty until you assign the values. It is a collection of same data types stored in a data structure of fixed size. įor example : When you write int a =2, a gets stored with binary value of 2 =0000 0010, first four bits are stored in one cell and other four bits in next adjacent cell. When you store data in a variable it gets converted into byte's, and each byte =8 bits, each block can hold 4 bits. Ĭredits : Q.How are variables stored in memory ? You can think ram as a box ,divided into smaller cells ,each cell holds equal data. Heap: Used to allocate big data of memory ,this is what we call Dynamic Memory.Stack: it's where some of your processor's information gets saved, for ex : functions ,variables, etc.There are two mechanism for storing data on your computer: Various classification of Data Structures: Ī real life example of data structure might be, your grocery list ,there are various ways you might write stuff on your list: Hello, this blog contains the basic concepts and applications of array, vector, linked list, stack, queue, priority queue, binary tree, binary search tree, heaps, threaded binary tree, graphs and hash tables.Īt the end it contains link to a GitHub repository, along with my another blog on different approaches to algorithms.ĭata Structure is a way of collecting and organizing data ,such that we can optimize our code.
