62.7k views
5 votes
Regarding a LinkedList, which of the following statements is/are true?

I. The "tail" reference reduces the time to add a new object at the end of a LinkedList.
II. The "head" reference reduces the time to add a new object at the end of a LinkedList.
III. The instance variable "count" reduces the time to add a new object at the end of a LinkedList. IV. The time needed to add an object to the front is fixed no matter how many objects are in the LinkedList.
a. I and IV only
b. II and IV only
c. I and III only
d. I, III and IV only

User Dina
by
8.0k points

1 Answer

4 votes

Final answer:

The 'tail' reference reduces the time to add a new object at the end of a LinkedList, the 'head' reference does not. The 'count' instance variable does not directly reduce the time. The time needed to add an object to the front is fixed.

Step-by-step explanation:

In a LinkedList, the "tail" reference points to the last node in the list, which makes it easier to add a new object at the end of the LinkedList, therefore, statement I is true.

The "head" reference, on the other hand, points to the first node in the list. Adding a new object at the end of the LinkedList requires traversing the entire list, so the "head" reference does not reduce the time for adding a new object at the end. Therefore, statement II is false.

The "count" instance variable in a LinkedList keeps track of the number of objects in the list. It does not directly affect the time to add a new object at the end of the LinkedList. Therefore, statement III is false.

The time needed to add an object to the front of a LinkedList is constant and does not depend on the number of objects in the list. Therefore, statement IV is true.

Therefore, the correct answer is d. I, III and IV only.

User Schlaus
by
8.2k points