Data Structure: Chapter 1 - Basic Concepts
Data Structure: Chapter 1 - Basic Concepts
} n=1000
i 0 i 0
m
n m
i
a
i 0
n i m
m
n m
a , for n 1.
i 0
i
m
Therefore, let c ai , n0 1, we have
i 0
O(1)<O(logn)<O(n)<O(nlogn)<O(n2)<O(n3)<O(2n)<O(n!)
Definition [Theta]
• f(n) = Θ(g(n)) iff there exist positive constants c1, c2 and
n0 such that c1g(n)≦ f(n)≦c2g(n) for all n where n≧ n0.
– Example 1:
• 3n+2=Θ(n)
log 2 n
T (n) = O(1) + T (n/2)
= O(1) + O(1) + T (n/4) = O(1) + O(1) + … + T (0)
= O(log2n)O(1) = O(log2n)