Consider an array with numbers n that has maximal digits k (see the "Editing" section). Consider the radix collation program from here :
def radixsort( aList ): RADIX = 10 maxLength = False tmp, placement = -1, 1 while not maxLength: maxLength = True
buckets is basically a 2nd list of all numbers. However, only n values will be added to it. What is the complexity of the space O (k + n), not O (n)? Correct me if I am wrong, even if we look at the space used to extract numbers in a specific place, it uses only 1 (constant) memory space?
Change I would like to explain my understanding of k . Suppose I give the input [12, 13, 65, 32, 789, 1, 3] , the algorithm specified in the link will go through 4 passes (of the first while inside the function). Here k = 4, i.e. Maximum No. digits for any element of the array + 1. Thus, k is not. passageways. This is the same k involved in the time complexity of this algorithm: O(kn) , which makes sense. I cannot understand how it plays a role in cosmic complexity: O(k + n) .
python sorting algorithm radix-sort space-complexity
skr_robo
source share