2) a) What is the difference between arrays and lists? b) What are the pros and
ID: 3801577 • Letter: 2
Question
2)
a) What is the difference between arrays and lists?
b) What are the pros and cons of storing data in arrays and/or lists?
c) You are given 7 Giga Bytes worth of data that must be loaded in memory in a computer with 8GB of RAM. Which data structure would use: an array or a list? Why?
d) You are given 1 Giga Byte worth of data that must be loaded in memory in a computer with 8GB of RAM and to be used mainly by a binary-search algorithm. Which data structure would use: an array or a list? Why?
e) You are given 1 Giga Byte worth of data that must be loaded in memory in a computer with 8GB of RAM and to be used mainly by a membership keeper algorithm from a nationwide gym. Which data structure would use: an array or a list? Why?
Explanation / Answer
a) ****Differences between Array and List****
Arrays are the most common data structures used to store data. One memory block is allocated for the entire array which holds all the initialized (and rest of the uninitialized) elements of the array.
Array is collection of elements of same data type.
List is collection of heterogeneous elements.
Memory Allocation in array is static and continuous.
Memory Allocation in List is dynamic and Random.
Array: User need not have to keep in track of next memory allocation.
List: User has to keep in Track of next location where memory is allocated.
b) ***Pros and Cons of storing data in arrays and lists***
Advantages of using arrays:
Easier to use and access.
Faster access to the elements
Reason:Indexing is 0-based and the elements can be accessed in a constant time by using the index of the particular element a as the subscript.
Disadvantages of using arrays:
Fixed size - the size of the array is static
One block allocation - if we don't have enough memory to provide a single block (but you have sufficient scattered memory blocks) to allocate the space for the array then you'll need to defragment and other similar stuff to first create a free block of that size. This might be called as improper utilization of memory.
Complex position-based insertion - if we want to insert an element at a position already covered by some other element then we got to shift right by one position all the elements to the right of that position. This will vacate the position for us to insert the new element at the desired position. The more elements we have to the right of the desired position, the more expensive the process and as a result the time complexity increases.
Also, could you please let us know if the list you are referring here is linked list or generic lists?
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.