Time & Space Complexity

Quick Sort:

Time complexity: best case O(n*lgn), worst case O(n^2)

Space complexity: Best case O(lgn) -> call stack height

Worse case O(n^2) -> call stack height

Merge Sort

Time complexity: always O(n*lgn) because we always divide the array in halves.

Space complexity: O(lgn +  n)

上一篇:空间复杂度是什么?What does ‘Space Complexity’ mean? ------geeksforgeeks 翻译


下一篇:[Algorithm] Fibonacci Sequence - Anatomy of recursion and space complexity analysis