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

时间复杂度❗ #20

Open
HealUP opened this issue May 11, 2023 · 0 comments
Open

时间复杂度❗ #20

HealUP opened this issue May 11, 2023 · 0 comments
Labels
算法 记录刷题记录,代码随想录

Comments

@HealUP
Copy link
Owner

HealUP commented May 11, 2023

如图所示:
image-20230510150615098.png
(图来源不明,侵删,抱歉)

  • 常数阶:常数阶的操作数量与输入数据大小 n无关,即不随着 n的变化而变化

  • 对数阶:与指数阶正好相反,后者反映“每轮增加到两倍的情况”,而前者反映“每轮缩减到一半的情况”。对数阶仅次于常数阶,时间增长得很慢,是理想的时间复杂度。

  • 线性阶:常出现于单层循环

  • 线性对数阶:常出现于嵌套循环中,两层循环的时间复杂度分别为 O(log⁡n) 和 O(n) 。

    主流排序算法的时间复杂度都是 O(nlog⁡N) ,例如快速排序、归并排序、堆排序等

  • 平方阶:常出现于嵌套循环,外层循环和内层循环都为 O(n)

  • 指数阶:增长得非常快,在实际应用中一般是不能被接受的。若一个问题使用「暴力枚举」求解的时间复杂度是 O(2^n) ,那么一般都需要使用**「动态规划」或「贪心算法」**等算法来求解

@HealUP HealUP added the 算法 记录刷题记录,代码随想录 label May 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
算法 记录刷题记录,代码随想录
Projects
None yet
Development

No branches or pull requests

1 participant