帮助学习算法基础知识
我正在学习算法,需要你们帮助我。我是初学者,所以如果我的问题不清楚,请原谅我。在学习的同时,我看到了类似 NlogN、N^2 等的东西。
当谈到使用这些符号检查不同算法的效率/性能时,我并不太清楚。我非常了解对数,但它们在检查算法性能方面的使用方式让我很生气。
我问是否有人可以向我指出一个教程,其中解释了这些符号,以便我可以很好地掌握基础知识。我真的很想了解他们并且愿意学习。
感谢您的帮助。
卡普。
I am learning algorithms and need you guys to help me. I am a beginner so forgive me if my question is not clear. Whiles am learning i am seeing something like NlogN, N^2 etc.. and something like that.
I don't really understand it clearly when it comes to checking the efficiency/performance of different algorithms using these notations. I understand Logarithms very well but the way they are been used in relation to checking algorithms performance makes me mad.
I am asking if someone can point me to a tutorial where such notations are been explained so that i can get the basics very well. I really want to understand them and am willing to learn.
Thanks for your help.
Kap.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您所描述的称为big O 表示法。 这里是一个解释它的指南。
需要注意的重要一点是,该符号忽略了无关紧要的术语。如果你的算法需要 6X^2 + 3X + 12 秒来执行,其中 X 是正在处理的数据点的数量,只需将其称为 O(X^2),因为当 X 变大时,6 不会真正产生影响,3 和 12 也不会。
What you've described is called big O notation. Here is a guide explaining it.
An important thing to notice is that the notation ignores insignificant terms. If your algorithm takes 6X^2 + 3X + 12 seconds to execute, where X is the number of data points being processed, just call it O(X^2) because when X gets big, the 6 won't really make a difference, nor will the 3 nor the 12.
购买算法简介。您可以以实惠的价格购买二手版本。
和/或查看这些来自麻省理工学院的精彩在线视频讲座围绕上述书籍构建。
通过观看这些讲座,您将了解为什么有些算法具有对数时间复杂度,而有些算法具有指数时间复杂度等。
Buy Introduction to Algorithms. You can get a second hand version at an affordable price.
And/or view these great online video lectures from MIT built around aforementioned book.
By viewing those lectures, you'll understand how some algorithms have logarithmic time complexity, whereas some have exponential, etc.
这些只是函数,接收输入中的项目数量,并返回完成算法所需的操作次数(通常它们返回算法的限制因素,而不是特定的函数......更多关于 - 此处)。
Those are just functions, receiving the number of items in input, and returning how many operations it takes to complete the algorithm (usually they return the limiting factor of the algorithm, and not a specific function.. more on that - here).
http://www.amazon.com/Structures-Algorithm-Analysis-Allen-Weiss/ dp/0805390529 是最好的书之一,它将以出色的方式解释算法。
- 干杯
http://www.amazon.com/Structures-Algorithm-Analysis-Allen-Weiss/dp/0805390529 is one of the best books which will explain Algorithms in excellent way.
--Cheers
你说的是 Big-O 表示法。这种表示法是将算法的最坏可能运行时间描述为其输入大小的函数。
O(n^2) 意味着如果输入的大小为n(例如其中包含 n 个元素的列表),则该算法将需要 n^2 次传递才能在最坏的情况下执行 - case scenen(Big-O 是最坏情况;还有其他表示最佳情况和平均情况的符号)。如果您有一个 for 循环嵌套在另一个 for 循环中,并且两者都从 1 运行到n,则可能会发生这种情况。
O(nlogn) 类似。当您遍历树结构(例如二叉树)时通常会发生这种情况。
请注意,您可能永远不会看到类似 O(3n) 的情况,因为对于非常大的 n 值,常数 3 并不重要,因此它会被简化为 O(n)。
许多其他人已经发布了很好的链接供阅读。
You're talking about Big-O notation. This notation is a way of describing the worst possible running time of an algorithm as a function of its input size.
O(n^2) means that if the input has a size of n (such as a list with n elements in it), the algorithm will require n^2 passes through to execute in the worst-case scenarion (Big-O is worst case; there are other notations for best-case and average case). This could happen if you have a a for loop nested inside another, and both run from 1 to n.
O(nlogn) is similar. It usually happens when you are traversing a tree structure (such as a binary tree).
Note that you will probably never see something like O(3n) because for very large values of n, the constant 3 doesn't matter much, so it would be simplified to O(n).
Many of the others have already posted good links to read at.