Important points on Array ,Dynamic Array and Singly Linked List

       Important points on Array ,Dynamic Array and Singly Linked List


                    **** Array ****


1) Array works with a static memory.static memory means that the memory size is fixed and cannot be grow and shirck at the run time

2) In array memory is allocated at compile time.

example   int a[6];

3) This makes it impossible to append items when all six indices are filled with values.

4) Accessing any element in an array is faster as the element in an array can be directly accessed through the index.
   

      
                 ****  Dynamic Array ****



1) Dynamic array is different from static array dynamic array can not have fixed size.

2) Dynamic array works is that it resizes itself whenever it fully filled of space.this usually by doubling itself.

3) let's say you go to append an 11th item to your array.this will make your out of space causing it to create a bigger array that's double its size(20).

4) After this the old array of size 10 needs to copy all of its values over to the bigger array that has a size of 20.

5) Now the old array will tell your operating system to delete it making that memory free memory.

6) Result,the bigger array of size 20 will now append your 11th item to it.



                    **** Linked List ****



1) It is the collection of lists .some example like list of exam marks,list of teachers etc.
 
2) Linked list elements can be stored anywhere in the memory or randomly stored.

3) Linked list takes less time while performing any operation like insertion, deletion, etc.

4) when you need to insert some data.and you donn't know about how much data are coming in future or if you think about dynamic array then it take a lot of time while copying data in one array to newly created array. so you can use the singly linked list data structure. 

5) Accessing an element in a linked list is slower as it starts traversing from the first element of the linked list.        

要查看或添加评论,请登录

Lakshay Kamboj的更多文章

  • What is object in OOPs

    What is object in OOPs

    object is a real world entity.object is an instance of a class.

社区洞察

其他会员也浏览了