For LinkedList<E>

  • get(int index) is O(n)
  • add(E element) is O(1)
  • add(int index, E element) is O(n)
  • remove(int index) is O(n)
  • Iterator.remove() is O(1) <--- main benefit of LinkedList<E>
  • ListIterator.add(E element) is O(1) <--- main benefit of LinkedList<E>

For ArrayList<E>

  • get(int index) is O(1) <--- main benefit of ArrayList<E>
  • add(E element) is O(1) amortized, but O(n) worst-case since the array must be resized and copied
  • add(int index, E element) is O(n - index) amortized, but O(n) worst-case (as above)
  • remove(int index) is O(n - index) (i.e. removing last is O(1))
  • Iterator.remove() is O(n - index)
  • ListIterator.add(E element) is O(n - index)

相关文章:

  • 2022-12-23
  • 2022-02-24
  • 2021-07-11
  • 2022-01-08
  • 2022-12-23
  • 2021-06-26
  • 2021-06-13
  • 2021-11-27
猜你喜欢
  • 2021-05-29
  • 2021-12-24
  • 2022-12-23
  • 2022-12-23
  • 2021-11-04
  • 2021-11-05
相关资源
相似解决方案