You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
• Some extra space is used when we sort arr\text{arr}arr in place. The space complexity of the sorting algorithm depends on the programming language.
o In python, the sort method sorts a list using the Timsort algorithm, which is a combination of Merge Sort and Insertion Sort and uses O(n)additional space.
o In C++, the sort() function is implemented as a hybrid of Quick Sort, Heap Sort, and Insertion Sort, with worst-case space complexity of O(logn).
o In Java, Arrays.sort() is implemented using a variant of the Quick Sort algorithm which has a space complexity of O(logn).
• We then traverse both arrays and calculate the cumulative product sum, this step takes O(1) extra space.
• To sum up, the overall space complexity is O(n) for Python and O(logn) for C++ and Java.