Dynamic Array Expansion Factor - Python

556 views Asked by At

Considering that the python list is a dynamic array, why there is not an expansion factor observed for it when increasing the number of elements. In other words, when I keep adding/appending an integer (which in my system it has size of 4 bytes), the size of array keeps increasing only by 4 (meaning that it only allocates 4 new bytes for the new integer). As I understand, there must be an expansion factor for dynamic arrays to keep the expansion procedure efficient (I expect after adding some new elements to the list, after specific attempts, the size of the list to get increased by a factor, let's say 1.125 as some references suggest for Python). It gets more interesting when removing an element from the list. When removing/popping an element, the size does not change (meaning that for efficiency purposes it keeps the size of the list unchanged in some cases). How this contradiction can be addressed? Thanks for your time and help.

0

There are 0 answers