Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Consider this code that creates some Location objects Consider this code that cr

ID: 3600468 • Letter: C

Question

Consider this code that creates some Location objects Consider this code that creates some Location objects Consider this code that creates some Location objects 7. Suppose we implement the IntArrayBag class using two partially-filled, "parallel ar arrays instead of a single (partially-filled) array. The first array, data, holds the values of the items in the bag and the second array, dataCounts, holds a count of the number of times that the associated item is in the bag. In other words, data[i] is an integer in the ba and datacounts (1] is the number of times that integer is in the bag g, We assume that there is an instance variable manyDataItems that tells us how many of the entries from the partially-filled arrays data and dataCounts are used to hold items from the bag (so manyDataItems

Explanation / Answer

(a) Capcity is the size of the array data. It is an integear that defines the maximum elements that can be stored in the data array.Suppose the capcity is 10.Then the data array can store only ten elements

(b) The advantages of this implementation are

i. We can avoid duplicate entries in the data array and limit the size of the array

ii. The count of each elements in the data array can be stored, which will make computation of total items easy

(c) The disadvantages are

i. The overhead in maintaining 2 arrays is an overhead which needs more moemory requirement'

ii. The complexity of the program increases. New modulus need to be added

(d)

i. add element

ii. Remove element

}