Compare and contrast the advantages and disadvantages of arr
Compare and contrast the advantages and disadvantages of arrays and linked lists. Give an example problem that is best accomplished by an array. Give an example problem that is best accomplished with an array.
access directly with array while linked list take some time to access data. However, list can insert easily the value into middle of list while array needs to increase the capacity and copy behind part and fore part and input. Array\'s size is fixed while linked list has flexible size.
Stack or queue is well match with linked list because if push and pop from the end point of data structure.
array is good with when program needs random access.
Solution
Ex: 1,2,3,4,5 to be stored in array
a[0]=1, a[1]=2 etc..
in LL we have to create space for 1 and store the address next to it as null. next when we want to insert 2 we have to create address for 2 and store that address in pointer of 1. and so on==> 1->2->3->4->5.
Initiallly array size is to be definrd, but ll size can grown dynamically
| Array | Linked List |
| Collections of elements with same data type | Ordered collection of data conecting by links |
| Array elements are stored continuosly in memory | stored in the space available and are linked |
| can have random acess | but here it will be sequential access |
| takes more time for insertion and deletion because we are storing continuosly in the memory | it takes more time here as the value of the link needs to changed only |
| It is static memory allocation as we have to decide before | Dynamic we have to create space for each value stored |
| Can be 1D 2D and 3D | Singular, Doubly, circular |
| element is independent because we do not have connection with previous memory location | address of the element is stored in the link part |
| need extra space for pointer | need extra space for pointer |
