if I have the following with ls
an instance of scala.collection.immutable.List
:
will ls.init
make a copy of the first n-1 elements of ls
and then
give this copy back thus yielding a runtime of theta of n-1(because of the copy runtime)?
Does ls.tail
take O(1) (I imagine this would deconstruct ls
into head :: tail
and then give back tail
which would take O(1) given it's a single-linked-list)?
I actually need a collection that would give me O(1) init operation is there one that provides such running time for init?