Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8317339

Incorrect description of running time for add in ArrayList class docs

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • 8, 11, 17, 20, 21, 22, 23
    • core-libs

      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.

            smarks Stuart Marks
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: