Part 2
Java
Hira Awais
Lecturer (DCS)
DDSA (FOC)
Slide courtesy : Dr. Zahid Halim
The 5N+3 time bound is said to "grow asymptotically" like N
This gives us an approximation of the complexity of the
algorithm
Ignores lots of (machine dependent) details, concentrate on
the bigger picture
Big Oh Notation: Upper bound
Omega Notation: Lower bound
Theta Notation: Tighter bound
To denote asymptotic upper bound, we use O-notation.
For a given function g(n), we denote by O(g(n)) (pronounced
“big-oh of g of n”) the set of functions:
O(g(n))= { f(n) : there exist positive constants c and n0 such
that 0≤f(n)≤c∗g(n) for all n≥n0 }
Which function is better? 4000
10 n2 Vs n3 3500
3000
2500
10 n^2
2000
n^3
1500
1000
500
0
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Even though it is correct to say “7n - 3 is O(n3)”, a better
statement is “7n - 3 is O(n)”, that is, one should make the
approximation as tight as possible
Simple Rule:
Drop lower order terms and constant factors
7n-3 is O(n)
8n2log n + 5n2 + n is O(n2log n)