Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

归并排序 #109

Open
hunterhug opened this issue May 26, 2021 · 4 comments
Open

归并排序 #109

hunterhug opened this issue May 26, 2021 · 4 comments

Comments

@hunterhug
Copy link
Owner

https://hunterhug.github.io/goa.c/#/algorithm/sort/merge_sort

Description

@baici1
Copy link
Contributor

baici1 commented Jan 1, 2022

你在自底而上归并排序里面对于空间复杂度的分析有问题!
从你的描述中感觉空间复杂度只和函数递归栈有关,但是你的算法中用到一个N长度的辅助数组,其实我觉得空间复杂度为O(N)。
这是我的看法。

@baici1
Copy link
Contributor

baici1 commented Jan 2, 2022

那个手摇算法在leetcode上面使用,我觉得可以填上去。
题目:剑指Offer58-II.左旋转字符串
leetcode 还是有用的!哈哈哈哈哈哈

@hunterhug
Copy link
Owner Author

@baici1
你在自底而上归并排序里面对于空间复杂度的分析有问题!
从你的描述中感觉空间复杂度只和函数递归栈有关,但是你的算法中用到一个N长度的辅助数组,其实我觉得空间复杂度为O(N)。
这是我的看法。

文章下面的手摇算法就节省了辅助数组的空间。如果没有原地排序,你确实可以说空间复杂度是O(N),但是根据上下文,我们讨论的是两种方法的区别,空间上的复杂度只要考虑的是递归,自顶向下空间复杂度更大。

@hunterhug
Copy link
Owner Author

@baici1
那个手摇算法在leetcode上面使用,我觉得可以填上去。
题目:剑指Offer58-II.左旋转字符串
leetcode 还是有用的!哈哈哈哈哈哈

实际上,不是leetcode有用,你要明白这一点。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants