Technical question on complexity.

Jerzy Karczmarczuk karczma at info.unicaen.fr
Thu Oct 13 12:12:01 EDT 2005


Anybody knows where I can find a concrete and guaranteed answer to the following
extremely basic and simple question?

What is the complexity of appending an element at the end of a list?
Concatenating with another?

The point is that I don't know what is the allocation policy... If Python lists
are standard pointer-chained small chunks, then obviously linear. But perhaps
there is some optimisation, after all a tuple uses a contiguous chunk, so it
*might* be possible that a list is essentially equivalent to an array, with its
length stored within, and adding something may be done in constant time (unless
the whole stuff is copied, which again makes the complexity related to the size
of existing structure...)

It is probably possible to retrieve this information from the sources, but I try
first an easier way.
Thank you.

Jerzy Karczmarczuk



More information about the Python-list mailing list