473,509 Members | 3,075 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Technical question on complexity.

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
Oct 13 '05 #1
1 1524
Jerzy Karczmarczuk wrote:
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?
amortized O(1)
Concatenating with another?
O(n)
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


a list consists of a single array of PyObject pointers, plus "allocated" and
"current size" fields. when you append, allocation is only done when needed,
and the new size is chosen carefully to keep the number of allocations low.
see the source for details (the exact "overallocation" strategy varies some-
what in different Python versions).

</F>

Oct 13 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
290
by: Brett | last post by:
This statement mentions that complexity kills but can it be avoided? "The kind of scalability I'm talking about is styem scale and compliexity. Anyone who has written large scale systems knows...
4
2798
by: Generic Usenet Account | last post by:
Consider two entities A and B such that there is a 1:n association between them. I mean that associated with each instance of A there are up to n instances of B. Currently in our software we are...
5
3917
by: junky_fellow | last post by:
How do we calculate the complexity of an algorithm? Am i right if i say the complexity of an algorithm is the number of comparisons done in that algorithm? thanx in advance .......
8
3880
by: sam_cit | last post by:
Hi, I came to read this particular statement with respect to reducing the complexity of a code, The usage of functional maps matrices instead of switch statements should be considered. I...
4
2751
by: raghu | last post by:
How to find the complexity of a C program? Can anyone explain it with an example... Thanks a lot.
26
7168
by: Lionel B | last post by:
Hi, Anyone know if the Standard has anything to say about the time complexity of size() for std::set? I need to access a set's size (/not/ to know if it is empty!) heavily during an algorithm...
5
1179
by: Joris van Lier | last post by:
Given two implementations of an algorithm how do I determine the relative computational complexity of each? Are there tools that can determine the relative performance of two algorithms or...
0
7234
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7344
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7412
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7069
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
5060
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4730
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1570
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
775
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
441
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.