Question

In: Computer Science

What are the advantages of a using a linked list rather than a conventional array in...

What are the advantages of a using a linked list rather than a conventional array in Java? and when would it be more efficient to use an array rather than a linked list? Explain your answer.

Solutions

Expert Solution

-> Linked list is a collection of data elements of same data type. it consists of two parts, one stores the data element and the other stores the address of the next element in the list.

-> Array is also the collection of data elements of the similar data type. unlike list, it stores only the data element.

Advantages of linked list over conventional array:

Linked list conventional array
linked list has dynamic memory allocation, any number of elements are added easily. array has a contiguous memory allocation, so the insertion of the elements will be difficult
linked lists are dynamic and flexible and can expand and contract its size easily. arrays are fixed in size.and if people who use arrays has to know the number of elements they are going to store priorly
operations like insertion , deletion are very fast. opeartions like insertion , deletions consumes a lot of time
linked list uses pointers to access the elements. hence using pointers the access will be very fast array uses index to access elements. accessing is slow compared to linked list.

-> when to use an array

  • when you are working on small projects it is better to use arrays because it takes less memory than linked list as the list contains an extra field of pointers and consumes more memory
  • when you know what must be the array size priorly then it is efficient to use arrays.
  • linked list is not efficient in random access. arrays are efficient because it has contiguous memory allocation and so any element will be physically near its neighbours and also the access will be easy/quick.
  • when you want to make the sorting of elements more easy then using arrays is efficient because it deals with only the indexes and easy to sort whereas in linked list it will involves complexity because you need to change the links of whole list.

Therefore , each has its own advantages and disadvantages , you have to make use of them according to the requirement.


Related Solutions

What are the advantages and disadvantages of using ranks rather than continuous measurements to conduct tests...
What are the advantages and disadvantages of using ranks rather than continuous measurements to conduct tests of hypotheses?
What are some advantages and challenges of using a logic-driven analytics process rather than follow a...
What are some advantages and challenges of using a logic-driven analytics process rather than follow a data-driven analytics process??
What are the advantages if breathing through the nose rather than the mouth?
What are the advantages if breathing through the nose rather than the mouth?
What are the advantages of targeting candy bars to adults rather than to children?
What are the advantages of targeting candy bars to adults rather than to children?
1. What are the advantages and disadvantages of investing with an investment company rather than buying...
1. What are the advantages and disadvantages of investing with an investment company rather than buying securities directly?
What are 4 advantages and 4 disadvantages of collective funds rather than individuals investing on their...
What are 4 advantages and 4 disadvantages of collective funds rather than individuals investing on their own?
What are the advantages of focussing on the unemployment rate reduction rather than debt reduction? (Include...
What are the advantages of focussing on the unemployment rate reduction rather than debt reduction? (Include some examples)
1. What are the advantages of targeting candy bars to adults rather than to children? 2....
1. What are the advantages of targeting candy bars to adults rather than to children? 2. Does targeting to adults require a change in image for candy products? 3. Why do you think bite-size candies are so popular with adults? 4. Describe your most recent purchase of a candy bar in terms of relevant affect and cognition, behavior, and environments.
) List five different advantages of composite materials over conventional materials.
) List five different advantages of composite materials over conventional materials.
List the advantages of using sheet metal parts ? List the advantages and disadvantages of using a lubricant in forging ?
  List the advantages of using sheet metal parts ? List the advantages and disadvantages of using a lubricant in forging ?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT