6) In each of the following situations which would be better, anarray-based impl
ID: 3610675 • Letter: 6
Question
6) In each of the following situations which would be better, anarray-based implementation of a list (A) or a node-basedimplementation of a list (N).A) I'm adding integers to the end of my list. I'm inserting alot of integers, but I'm only removing them occasionally and I'mlooking up items in my list a lot.
B) I'm inserting and deleting exactly as much as I'm looking up andmy items are characters. My list is around 500characters.
C) I'm inserting and deleting exactly as much as I'm looking up andmy items are very large objects. My list is around 500objets.
D) I'm inserting and deleting exactly as much as I'm lookingup. My list is growing very fast.
E) I'm reorganizing my list regularly.
-------------------------------------------------------------------------------------------------------
So I am not sure if I am right but I think the answers are:
A) Node (N)
B) Array (A)
C) Node (N)
D) Node (N)
E) Node (N)
Can someone tell me what they think and maybe explain why?
Explanation / Answer
In an array, thememory cells of the array are linked with each other. It means thatthe memory of the array is contiguous. In an array, it isimpossible that one element of the array is located at a memorylocation while the other element is located somewhere far from itin the memory. It is located in very next location in the memory.It is a property of the array that its elements are placed togetherwith one another in the memory. Moreover, when we have declared thesize of the array, it is not possible to increase or decrease itduring the execution of the program. If we need more elements tostore in the array, there is need of changing its size in thedeclaration. We have to compile the program again before executingit. Now array will be of the new size. But what happens if we againneed to store more elements? We will change the code of our programto change the declaration of the array while recompilingit.
Suppose we haveused the dynamic memory allocation and created an array of 100elements with the use of new operator. In case of need of200 elements, we will release this array and allocate a new arrayof 200 elements. Before releasing the previous array, it willwise to copy its elements to the new array so that it does not loseany information. Now this new array is in ‘ready foruse’ position. Thus the procedure of creating a new array isnot an easy task.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.