Question: Given the size method of Exercise E16.6 and the get method of Exercise P16.3, what is the big-Oh efficiency of this loop? Data

Given the size method of Exercise • E16.6 and the get method of Exercise ••• P16.3, what is the big-Oh efficiency of this loop?

for (int i = 0; i < myList.size(); i++) { System.out.println(my List.get(i));

Data from exercise E16.6

Add an instance variable currentSize to our implementation of the LinkedList class.
Modify the add, addLast, and remove methods of both the linked list and the list iterator to update the currentSize variable so that it always contains the correct size. Change the size method of Exercise • E16.4 so that it simply returns the value of currentSize.

Data from exercise p16.3

Improve the efficiency of the get and set methods of Exercise • P16.1 by storing (or “caching”) the last known (node, index) pair. If n is larger than the last known index, start from the corresponding node instead of the front of the list. Be sure to discard the last known pair when it is no longer accurate. (This can happen when another method edits the list).

for (int i = 0; i < myList.size(); i++) { System.out.println(my List.get(i)); }

Step by Step Solution

3.41 Rating (157 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

The loop provided in the image appears to iterate over each element of a LinkedList by using the siz... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Java Programming Questions!