A DESCRIPTION OF THE PROBLEM :
The ArrayList documentation states : "The add operation runs in amortized constant time, that is, adding n elements requires O(n) time."
This is correct for add(E e), but is not correct for the method add(int index, E element), which does not run in amortized constant time, but rather in O(n) time.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Visit the java documentation for <ArrayList> and check the second paragraph : "The add operation runs in amortized constant time, that is, adding n elements requires O(n) time. All of the other operations run in linear time (roughly speaking). "
https://docs.oracle.com/en/java/javase/20/docs/api/java.base/java/util/ArrayList.html
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Expected that add(int index, E element) would show the correct running time analysis.
ACTUAL -
Documentation states "add" takes amortized constant time, which implies this applies to both "add" methods, and is incorrect.
The ArrayList documentation states : "The add operation runs in amortized constant time, that is, adding n elements requires O(n) time."
This is correct for add(E e), but is not correct for the method add(int index, E element), which does not run in amortized constant time, but rather in O(n) time.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Visit the java documentation for <ArrayList> and check the second paragraph : "The add operation runs in amortized constant time, that is, adding n elements requires O(n) time. All of the other operations run in linear time (roughly speaking). "
https://docs.oracle.com/en/java/javase/20/docs/api/java.base/java/util/ArrayList.html
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Expected that add(int index, E element) would show the correct running time analysis.
ACTUAL -
Documentation states "add" takes amortized constant time, which implies this applies to both "add" methods, and is incorrect.