Why is mergesort space complexity O(log(n)) with linked lists? Why is mergesort space complexity O(log(n)) with linked lists? arrays arrays

Why is mergesort space complexity O(log(n)) with linked lists?


The mergesort algorithm is recursive, so it requires O(log n) stack space, for both the array and linked list cases. But the array case also allocates an additional O(n) space, which dominates the O(log n) space required for the stack. So the array version is O(n), and the linked list version is O(log n).


Mergesort is a recursive algorithm. Each recursive step puts another frame on the stack. Sorting 64 items will take one more recursive step than 32 items, and it is in fact the size of the stack that is referred to when the space requirement is said to be O(log(n)).