In: Computer Science
A good strategy to manage the memory consumed by an array-based implementation of ListInterface is
Group of answer choices
to quadruple the size of the array when it is full and to cut it to one quarter when it is one quarter full
to double the size of the array when it is full and to cut it to half when it is half full
to triple the size of the array when it is full and to cut it to half when it is half full
to double the size of the array when it is full and to cut it to 3/4 when it is one half full
All of the above
When removeGap(pos) method of an array-based implementation of ListInterface is called, no entries will be moved if pos is equal to
Group of answer choices
numberOfEntries
numberOfEntries – 1
1
0
None of the above
Our AList (array-based) implementation of the List interface has an initial capacity of 25 elements. We add 101 items using the method add(). We then remove 50 items using the method remove(). Assuming that remove() doesn't change the size of the array, what is the length of the array after the last call to remove()?
Note that length of array can be different from the number of entries in the array.
Group of answer choices
50
51
75
100
200
In an array-based implementation of ListInterface, what is the time complexity of removing an entry from the end of the list when remove() doesn't change the length of the array?
Group of answer choices
O(1)
O(log n)
O(n)
O(n2)
none of the above
1. A good strategy to manage the memory consumed by an array-based implementation of ListInterface is
All the above because one cant expect the amount of memory that need to be allocated exactly making wrong predictions and getting OutOfMemory error.
This is recommended as a better practice .
2. When removeGap(pos) method of an array-based implementation of ListInterface is called, no entries will be moved if pos is equal to
When pos is equal to numberOfEntries – 1 then it is referring to the last index. Removing last index value does not affect the original List so no entries need to move.
3.Our AList (array-based) implementation of the List interface has an initial capacity of 25 elements. We add 101 items using the method add(). We then remove 50 items using the method remove(). Assuming that remove() doesn't change the size of the array, what is the length of the array after the last call to remove()?
Initially the capacity was 25 so length was 25 now, but none of them are filled after adding 101 elements first 25 will get filled once and then for the rest of them new memory will be created so the length of the array becomes 101 now. As 50 elements were none of the memory was deleted but the number of elements would be 101-50=51 so length is 51.
4. In an array-based implementation of ListInterface, what is the time complexity of removing an entry from the end of the list when remove() doesn't change the length of the array?
To remove an element by value in ArrayList and LinkedList we need to iterate through each element to reach that index and then remove that value. This operation is of O(N) complexity.