大O标记法
源起
一、概念
大O表示法就是将算法的所有步骤转换为代数项,然后排除不会对问题的整体复杂度产生较大影响的较低阶常数和系数。
大O表示法可以告诉我们算法的快慢。
大O比较的是操作数,它指出了算法运行时间的增速。
O(n) 括号里的是操作数。
二、常见的大O运行时间
O(log n),也叫对数时间,二分查找。
O(n),也叫线性时间,简单查找。
O(n * log n),快速排序——一种速度较快的排序算法。
O(n²),选择排序——一种速度较慢的排序算法。
O(n!),旅行商问题的解决方案——一种非常慢的算法。
参考资料