1. 程式人生 > >ADA演算法知識(一)

ADA演算法知識(一)

a) Consider the following statements. Which ones are true?

(i) If f(n) = nlogn, g(n)=(logn)^2+n , then g(n) is Omega(f(n)).

(ii) If f(n) = 1.3^n, g(n) = 30n^5+200n^3, then f(n) is O(g(n)).

(iii) If f(n) = n^2log _{5}n,g(n) = nlog(n) + 3n^2\log_{2}(n+2), then f(n) is \theta(g(n))

 

At first, (logn)^2<n , it is obviously , so g(n) time complexity is O(n),and f(n) time complexity is O(nlogn), so O(n)<O(nlogn), so f(n)>g(n),so g(n) is O(f(n)), but the first statement shows that g(n) is Omega(f(n)) ,which is wrong, so the first question is false.

Second, it is obviously that f(n)>g(n), so g(n) is O(f(n)) , f(n) is Omega(g(n)), so the second question is false too.

Third , it is obviously that f(n) is \theta(g(n)) , it is true

如果光是要記住如何做題的話,只需要記住當g(n)<=f(n)的時候,g(n)=O(f(n))

b)Compute gcd(92142,21618) using Euclid's algorithm. Show all working.

(92142,21618)

92142/21618 = 4 ······ 5670

21618/5670 =  3 ······ 4608

5670/4608 = 1 ······ 1062

4608/1062 = 4 ······ 360

1062/360 = 2 ······ 342 

360/342 = 1 ······ 18

342/18 = 19

so 18 is the euclid , we get the result