Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the time complexity of accessing an element of a List by index in Dart?

Tags:

Lists in Dart are dynamically sized unless you specify a size at creation.

So I would think the dynamically sized one would work like ArrayList in Java, and the statically sized one would work like [] in Java.

Is this correct, or is it always O(1) access? Or always O(n) access?

I haven't been able to find any resources about this online.

like image 732
lbenedetto Avatar asked Apr 15 '18 06:04

lbenedetto


1 Answers

The runtime complexity is of course O(1).

I haven't found a list implementation in Dart core where it might be O(n) but I might have missed one.

I assume it would be O(n) for https://api.dartlang.org/stable/1.24.3/dart-collection/LinkedList-class.html

like image 68
Günter Zöchbauer Avatar answered Oct 04 '22 19:10

Günter Zöchbauer