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

For a certain application, objects have two methods. One method returns a String

ID: 3643367 • Letter: F

Question

For a certain application, objects have two methods. One method returns a String, name, and the other method returns an integer value, score, both to be stored in a data structure. The following operations will be performed on the data structure:
1. adding an undetermined number of objects, which is done once
2. looking up an object by name and changing its score, which is done frequently
3. finding the object with the highest score, which is done occasionally, much less frequently than operation 2.

Which of the following data structures would be the most appropriate for this task?

A.) An unordered array (objects are in the array in the order entered, unordered by name or score)
B.) An array ordered by name
C.) An array ordered by score
D.) An unordered ArrayList (objects are in the ArrayList in the order entered, unordered by name or score)
E.) An ArrayList ordered by name

Explanation / Answer

please rate

Answer is e) an ArrayList ordered by name.

a) is not suitable becaue since names are not sorted entire array has to be searched also array cannot grow dynamically (disadvantage because adding an undetermined number of objects, which is done once).

B) is not suitable because array cannot grow dynamically (disadvantage because adding an undetermined number of objects, which is done once).

C) is not suitable because score is queried less frequently and names have to be searched each time in the entire list also array cannot grow dynamically (disadvantage because adding an undetermined number of objects, which is done once).

D) unordered ArrayList performs less efficiently on looking up an object by name and changing its score, which is done frequently