ArrayList的是复杂的indexOf N + [英] Is ArrayList indexOf complexity N?
问题描述
我在ArrayList的N个数字。要获得的indexOf
,ArrayList的将迭代最大的N倍,所以复杂性是 O(N)
,是是否正确?
I have N numbers in arraylist. To get the indexOf
, arraylist will have to iterate maximum N times, so complexity is O(N)
, is that correct?
推荐答案
源代码的的Java API
是的,复杂度为O(N)。
Yes,Complexity is O(N).
大小的isEmpty,获取,设置,迭代器的ListIterator和操作在固定时间内运行。该加载操作在固定的时间运行,即,添加n个元素需要O(n)的时间。其他所有操作都以线性时间运行(粗略地讲)。相比,LinkedList实现的常数因子较低。
The size, isEmpty, get, set, iterator, and listIterator operations run in constant time. 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). The constant factor is low compared to that for the LinkedList implementation.
这篇关于ArrayList的是复杂的indexOf N +的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!