algorithm-analysis
algorithm-analysis
• Big Ω:
T(n) = Ω(g(n)) if there are constants c and n0 such
that T(n) >=cg(n) when n >=n0.
• Big Ө:
T(n) = Ө(h(n)) if and only if T(n) = O(h(n)) and T(n) = Ω(h(n)).
if( cond )
S1
else
S2
the running time of an if/else statement is never more than the running
time of the test plus the larger of the running times of S1 and S2.
• Example:
For input -2, 11, -4, 13, -5, -2, the answer is 20
(a2through a4).
The algorithm works by continually computing remainders until 0 is reached. The last
nonzero remainder is the answer. Thus, if m = 1,989 and n = 1,590,
then the sequence of remainders is 399, 393, 6, 3, 0.
Therefore, gcd (1989, 1590) = 3. As the example shows, this is a fast algorithm.
Prof. Sainath Patil, VCET Vasai Rd..