Lucas P Melo wrote:
> Hello,
> I would like to know how much it costs to insert an element into a list
> using this operation:
> a[2:2] = [ 1 ]
> i. e, what is the complexity of the operation above (given that len(a) =
> n)?
O(n) I'd say. You need to copy nearly the whole list, and sometimes
re-a
Robert Kern wrote:
O(n). Python lists are contiguous arrays in memory, and everything
after the insertion point needs to be moved. Raymond Hettinger has a
good talk about the implementation of Python lists and other container
objects.
http://www.youtube.com/watch?v=hYUsssClE94
http://www.pyco
On 2009-07-21 14:21, Lucas P Melo wrote:
Hello,
I would like to know how much it costs to insert an element into a list
using this operation:
a[2:2] = [ 1 ]
i. e, what is the complexity of the operation above (given that len(a) =
n)?
O(n). Python lists are contiguous arrays in memory, and every
On Tue, Jul 21, 2009 at 2:21 PM, Lucas P Melo wrote:
> I would like to know how much it costs to insert an element into a list
> using this operation:
> a[2:2] = [ 1 ]
> i. e, what is the complexity of the operation above (given that len(a) =
> n)?
>
O(n)
If you want O(log n), you can use the b
Hello,
I would like to know how much it costs to insert an element into a list
using this operation:
a[2:2] = [ 1 ]
i. e, what is the complexity of the operation above (given that len(a) = n)?
Thanks.
--
http://mail.python.org/mailman/listinfo/python-list