Question

In: Computer Science

A good strategy to manage the memory consumed by an array-based implementation of ListInterface is Group...

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

Solutions

Expert Solution


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.



Related Solutions

Write an array-based implementation of the ADT list that expands the size of the array of...
Write an array-based implementation of the ADT list that expands the size of the array of list entries as needed so that the list can always accommodate a new entry. Also reduce the size of the array as needed to accommodate several removals. When the size of the array is greater than 20 and the number of entries in the list is less than half the size of the array, reduce the size of the array so that it is...
Please make an Array-based implementation of a Binary Tree in Python based on the given file...
Please make an Array-based implementation of a Binary Tree in Python based on the given file below. Make sure to keep the Abstract Data File of the starter code below when building the Array-based implementation. Python Starter Code Given Below: class ArrayBinaryTree(BinaryTree): """Linked representation of a binary tree structure.""" # -------------------------- nested _Node class -------------------------- class _Node: def __init__(self, element, parent=None, left=None, right=None): # -------------------------- nested Position class -------------------------- class Position(BinaryTree.Position): """An abstraction representing the location of a single element."""...
Using the implementation of the array based list given, write a CLIENT method (that is NOT...
Using the implementation of the array based list given, write a CLIENT method (that is NOT part of the class) called replace, that given a value and a position replaces the value of the element at that position. REMEMBER error checking public static void replace( List aList, int newValue, int position) public class ArraybasedList implements MyListInterface{ private static final int DEFAULTSIZE = 25; // Data members: private int currentSize; private int maxSize; private S[] elements; //default constructor has NO parameters...
the goal is for you to develop an approach that improves up on the array-based implementation...
the goal is for you to develop an approach that improves up on the array-based implementation in some way.For example, perhaps you want to take an approach that avoids the cost of re-allocating the array when it's full,e.g. using a linked-list. Of course, with a linked-list the cost of accessing an element will jump from O(1) to O(N), so that’s a costly trade-off. Perhaps you can think of a better approach that avoids the cost of reallocating the array, while...
More than a good strategy is needed for a risk management plan. Implementation of the plan...
More than a good strategy is needed for a risk management plan. Implementation of the plan must be practiced and maintained. Complete the following assignment: Discuss why each of the following components must be considered in plan implementation: Rehearsal Maintenance Benchmarking Assurance and Audit The completed assignment should be at least 250 words.
Implementation of a a queue with a "circular" array or a "regular" array. (a) "circular" array:...
Implementation of a a queue with a "circular" array or a "regular" array. (a) "circular" array: consider using the smallest number of fields/variables in a struct/class. List the fields/variables that support the enqueue and dequeue operations in O(1) time in the worst case. Explain why the list is the smallest and the two operations are O(1) time. (b) "regular" array: explain the worst-case time complexity in big-O for the operations (queue size is at most n).
Give an example of a time when an organization had good strategy formulation but poor implementation...
Give an example of a time when an organization had good strategy formulation but poor implementation and this resulted in failure.
What is strategy implementation? What questions must strategy makers consider to begin the implementation process?
What is strategy implementation? What questions must strategy makers consider to begin the implementation process?
Create an array-based implementation of a binary tree. (WRITE IN JAVA) DON'T FORGET TO INCLUDE PSEUDOCODE...
Create an array-based implementation of a binary tree. (WRITE IN JAVA) DON'T FORGET TO INCLUDE PSEUDOCODE AND UML DIAGRAM
Create an array-based implementation of a binary tree. DON'T FORGET TO INCLUDE PSEUDOCODE AND UML DIAGRAM
Create an array-based implementation of a binary tree. DON'T FORGET TO INCLUDE PSEUDOCODE AND UML DIAGRAM
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT