400 views
0 votes
0 votes
In an array A[n] of size n we can access the element A[n+1] by writting *(A+n+1) . Accessing the all the elements before and after the index can be done in 0(1) time complexity.So, why we will use a linked list if we can access any no of elements after the end point of an array . The   size of each node is also larger in case of linked list.

1 Answer

1 votes
1 votes
why we use link list is that there are various thing u need to know . so one by one . there is something called bound checking which is not a feature of c but a feature of c++ . whenever u are going to acess data out of array it is going to give u error. so why we need to go for bound checking because to maintain order of one acess time the array must be stored in sequencial order. and if we say a[5] system allocate all the memory in continious manner to the array . while the memory after that may not be free. if we just go writing it . it may overwrite the data of other program . whereas linklist are dynamic in nature . so no need of continous allocation so. array are not used .it may have worked. but this type of programming is a hazard to system.

Related questions

0 votes
0 votes
5 answers
1
radha gogia asked Sep 30, 2015
1,656 views
If I am given an array $X$ of $n$ distinct integers which is interpreted as a complete binary tree, so if the parent is at index $i$, then it's left child would be at ind...
8 votes
8 votes
2 answers
2
0 votes
0 votes
1 answer
3
dhruba asked Jun 5, 2023
441 views
Consider performing QuickSort on an array of n distinct elements. What is the probability that no comparisons will be made between the smallest and largest element?a. 1/n...
3 votes
3 votes
2 answers
4