美文网首页
2019-02-06 Basic Algorithms Lec4

2019-02-06 Basic Algorithms Lec4

作者: ANPULI | 来源:发表于2019-02-07 22:41 被阅读0次

Recursion

function Sums(S, A[1..n])
result = 0
for i from 1 to n
for j from i to n
if A[i]+A[j] = S
result = result + 1
return result

\frac{n(n+1)}{2}

talk about runtime
can can not
predict how it scales predict actual runtime

Big-O and \theta notation

Properties:

  1. ignore slow-growing things
  2. reason about relaative growth, e.g., n^2 2n^2 and \frac{n^2}{2} should be the same

Definition

We shall say that f(n) = O(g(n)) if there exist C, N > 0 such that f(n)\leq C\cdot g(n) for all n > N
For an algorithm with runtime O(n^2), is it true that n\rightarrow 2n \Longrightarrow runtime \rightarrow 4runtime?
No, it just says the algorithm is NOT WORSE THAN O(n^2).

相关文章

网友评论

      本文标题:2019-02-06 Basic Algorithms Lec4

      本文链接:https://www.haomeiwen.com/subject/dhhwsqtx.html