chapter_computational_complexity/time_complexity/ #18
Replies: 154 comments 230 replies
-
Beta Was this translation helpful? Give feedback.
-
本页中n^2的讲解中,以「冒泡排序」为例,外层循环n-1 次,内层循环···次,平均为n/2次,因此时间复杂度为 ··· 。在这里计算的是最差时间复杂度,是不是描述应该为计算内层冒泡排序次数的等差数列求和,而不是平均n/2再乘以外层(n-1)的描述,感觉容易造成歧义。 |
Beta Was this translation helpful? Give feedback.
-
最差 O 平均 θ 最优 Ω |
Beta Was this translation helpful? Give feedback.
-
大佬好,界面是不是加一个“返回顶部”的按钮会更方便些呀; |
Beta Was this translation helpful? Give feedback.
-
大佬你好,我是一个算法小白,在看公式时就有了困难,比如这个公式T(n)= 3 +2n,文中也没有具体写是怎么推导出来的,不仅如此,其他公式的推导好像也没有太详细。不知我是不是还该继续看下去。 |
Beta Was this translation helpful? Give feedback.
-
指数阶, 那个代码里面应该是 return expRecur(n - 2) + expRecur(n - 1) + 1吧; |
Beta Was this translation helpful? Give feedback.
-
哈喽,k大,worst_best_time_complexity.cpp 代码编译时出错 ➜ chapter_computational_complexity git:(master g++ worst_best_time_complexity.cpp
worst_best_time_complexity.cpp: In function ‘std::vector<int> randomNumbers(int)’:
worst_best_time_complexity.cpp:17:21: error: ‘chrono’ has not been declared
17 | unsigned seed = chrono::system_clock::now().time_since_epoch().count();
| ^~~~~~
worst_best_time_complexity.cpp:19:5: error: ‘shuffle’ was not declared in this scope
19 | shuffle(nums.begin(), nums.end(), default_random_engine(seed));
| ^~~~~~~ 原因是在
添加后编译通过,运行正常 ➜ chapter_computational_complexity git:(master g++ worst_best_time_complexity.cpp -o worst_best_time_complexity
➜ chapter_computational_complexity git:(master ls worst_best_time_complexity*
worst_best_time_complexity worst_best_time_complexity.cpp
|
Beta Was this translation helpful? Give feedback.
-
看不明白,这章好像只是知道了时间复杂度的表示方式。 |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
K神,阶乘阶的操作总数应该不是等于最底层结点数量吧,是所有结点中的操作总数之和吗? |
Beta Was this translation helpful? Give feedback.
-
指数阶这段没看懂count = 1 + 2 + 4 + 8 + .. + 2^(n-1) = 2^n - 1。为什么最后等于2^n - 1 |
Beta Was this translation helpful? Give feedback.
-
能看到这本书真的太好了 |
Beta Was this translation helpful? Give feedback.
-
我不太清楚是不是我的系统问题,这两天一直在看,前几天似乎没问题。今天起的教程似乎所有显示数学公式的地方都出了问题?比如2.2.4中的一段变成了这样: 以下示例展示了使用上述技巧前、后的统计结果。 Edge 和 Chrome 都有这样的显示问题 |
Beta Was this translation helpful? Give feedback.
-
学习数据结构画图太重要了,作者的图画的太棒啦,可以知道是什么软件画的吗 |
Beta Was this translation helpful? Give feedback.
-
/* 指数阶(递归实现) */
function expRecur(n: number): number {
if (n == 1) return 1;
return expRecur(n - 1) + expRecur(n - 1) + 1;
} 这是在求什么,为什么最后要+1。没懂这里,谢谢。如果不要+1应该是求最后一层树结点数量,再+1就不知道是求什么了。请问是我理解错了吗?能不能分析一下这个函数的复杂度,谢谢大佬。已经理解了,是求全部节点数量,即操作次数,没毛病。谢谢大佬。太巧妙了。 总结为:n层的总节点数是n-1层总结点数*2 + 1,第1层总数为1,所以可以这样递归写。 看完gpt的答案我也懂了,感觉可以参考gpt的回答改进一下。 上述函数的时间复杂度为指数阶(Exponential Time),记作O(2^n)。 在函数中,每次递归调用expRecur(n - 1)会导致另外两次递归调用,因此函数的递归深度将以指数级增长。每次递归调用的时间复杂度是常数级的,但由于递归的次数是指数级的,因此整体时间复杂度也是指数级的。 简单来说,随着输入n的增加,函数的执行时间将指数增长,导致非常低效。因此,这是一个效率较低的实现,特别是在处理大型输入时。如果需要更高效的实现,可以考虑使用其他算法或优化技巧来减少递归的次数。 |
Beta Was this translation helpful? Give feedback.
-
day2 |
Beta Was this translation helpful? Give feedback.
-
2025.3.11 |
Beta Was this translation helpful? Give feedback.
-
打卡 |
Beta Was this translation helpful? Give feedback.
-
如果有人回复我消息,我该在哪里看到消息提醒?还是说我要回到这个章节翻我之前的评论我才能看见吗?感谢解答! |
Beta Was this translation helpful? Give feedback.
-
/* 阶乘阶(递归实现) */ |
Beta Was this translation helpful? Give feedback.
-
“时间复杂度能够有效评估算法效率。例如,算法 B 的运行时间呈线性增长,在 n>1时比算法 A 更慢,在 |
Beta Was this translation helpful? Give feedback.
-
真诚提问,想请问下大家这本书看了适合新人吗,怎么样。我看了两天感觉很多概念很晦涩,递归,分治,各种排序。我是一个转码纯小白,刚学完python,不知道是不是有适合新人的数据结构与算法推荐。谢谢! |
Beta Was this translation helpful? Give feedback.
-
打卡 2025.6.9 2.常见类型的时间复杂度 与指数阶相反,对数阶反映了“每轮缩减到一半”的情况。 3.最佳、最差、平均时间复杂度 |
Beta Was this translation helpful? Give feedback.
-
大佬,2n+10000*(n10000)的时间复杂度不应该是O(n10000)吗?为什么表中是O(2n)? |
Beta Was this translation helpful? Give feedback.
-
请问这里的代码报错怎么办,我是运行了iteration.cpp文件,然后报错如下: |
Beta Was this translation helpful? Give feedback.
-
小学生第二天打卡,7.11 |
Beta Was this translation helpful? Give feedback.
-
我来稍微解释一下为什么“每轮缩减到原来的一半”意味着问题规模是对数阶。 因为每次操作后、n都变为原来的一半,所以操作k次后n变为n / 2^k。 |
Beta Was this translation helpful? Give feedback.
-
都能收到(悲)
获取Outlook for Android<https://aka.ms/AAb9ysg>
…________________________________
From: Kruogu ***@***.***>
Sent: Thursday, August 28, 2025 5:32:50 AM
To: krahets/hello-algo ***@***.***>
Cc: REN, Chenguang [Student] ***@***.***>; Comment ***@***.***>
Subject: Re: [krahets/hello-algo] chapter_computational_complexity/time_complexity/ (Discussion #18)
CAUTION: This email is not originated from PolyU. Do not click links or open attachments unless you recognize the sender and know the content is safe.
你只收到一条信息吗?这个楼下面所有人发出的信息我都可以收到
―
Reply to this email directly, view it on GitHub<#18 (reply in thread)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/BA23SQA72IZONENES4OL66D3PYPYFAVCNFSM6AAAAAASLISNF6VHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTIMRTG43TEMQ>.
You are receiving this because you commented.Message ID: ***@***.***>
[https://www.polyu.edu.hk/emaildisclaimer/PolyU_Email_Signature-v2.jpg]
Disclaimer:
This message (including any attachments) contains confidential information intended for a specific individual and purpose. If you are not the intended recipient, you should delete this message and notify the sender and The Hong Kong Polytechnic University (the University) immediately. Any disclosure, copying, or distribution of this message, or the taking of any action based on it, is strictly prohibited and may be unlawful.
The University specifically denies any responsibility for the accuracy or quality of information obtained through University E-mail Facilities. Any views and opinions expressed are only those of the author(s) and do not necessarily represent those of the University and the University accepts no liability whatsoever for any losses or damages incurred or caused to any party as a result of the use of such information.
|
Beta Was this translation helpful? Give feedback.
-
我都能收到,不过可以退订,就不会有很多人打扰了
…------------------ 原始邮件 ------------------
发件人: "krahets/hello-algo" ***@***.***>;
发送时间: 2025年8月28日(星期四) 中午11:25
***@***.***>;
***@***.******@***.***>;
主题: Re: [krahets/hello-algo] chapter_computational_complexity/time_complexity/ (Discussion #18)
都能收到(悲)
获取Outlook for Android<https://aka.ms/AAb9ysg>
________________________________
From: Kruogu ***@***.***>
Sent: Thursday, August 28, 2025 5:32:50 AM
To: krahets/hello-algo ***@***.***>
Cc: REN, Chenguang [Student] ***@***.***>; Comment ***@***.***>
Subject: Re: [krahets/hello-algo] chapter_computational_complexity/time_complexity/ (Discussion #18)
CAUTION: This email is not originated from PolyU. Do not click links or open attachments unless you recognize the sender and know the content is safe.
你只收到一条信息吗?这个楼下面所有人发出的信息我都可以收到
―
Reply to this email directly, view it on GitHub<#18 (reply in thread)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/BA23SQA72IZONENES4OL66D3PYPYFAVCNFSM6AAAAAASLISNF6VHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTIMRTG43TEMQ>.
You are receiving this because you commented.Message ID: ***@***.***>
[https://www.polyu.edu.hk/emaildisclaimer/PolyU_Email_Signature-v2.jpg]
Disclaimer:
This message (including any attachments) contains confidential information intended for a specific individual and purpose. If you are not the intended recipient, you should delete this message and notify the sender and The Hong Kong Polytechnic University (the University) immediately. Any disclosure, copying, or distribution of this message, or the taking of any action based on it, is strictly prohibited and may be unlawful.
The University specifically denies any responsibility for the accuracy or quality of information obtained through University E-mail Facilities. Any views and opinions expressed are only those of the author(s) and do not necessarily represent those of the University and the University accepts no liability whatsoever for any losses or damages incurred or caused to any party as a result of the use of such information.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you commented.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
从这章开始变得难啃了 o(╥﹏╥)o |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
chapter_computational_complexity/time_complexity/
动画图解、一键运行的数据结构与算法教程
https://www.hello-algo.com/chapter_computational_complexity/time_complexity/
Beta Was this translation helpful? Give feedback.
All reactions