ArrayList的是复杂的indexOf N + [英] Is ArrayList indexOf complexity N?

查看:161
本文介绍了ArrayList的是复杂的indexOf 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆