Data Strucutres and Algorithms
Data Strucutres and Algorithms
ALGORITHMS
(JAVA)
Important Point:
PROPERTIES
1. Reflexivity:
For any function f(n), f(n) = O(f(n)).
Example:
2. Transitivity:
If f(n) = O(g(n)) and g(n) = O(h(n)), then f(n) =
O(h(n)).
Example:
3. Constant Factor:
For any constant c > 0 and functions f(n) and g(n),
if f(n) = O(g(n)), then cf(n) = O(g(n)).
Example:
4. Sum Rule:
If f(n) = O(g(n)) and h(n) = O(g(n)), then f(n) +
h(n) = O(g(n)).
Example:
5. Product Rule:
If f(n) = O(g(n)) and h(n) = O(k(n)), then f(n) * h(n)
= O(g(n) * k(n)).
Example:
6. Composition Rule:
If f(n) = O(g(n)) and g(n) = O(h(n)), then f(g(n)) =
O(h(n)).
Example:
n log( n n* n^ 2^n n!
n) log(n) 2
1 1 10
1 10 1024 3628800
0 0 0
O(n log
Superlinear Heap Sort, Merge Sort
n)
O(nlogn) O(nlogn
33.2 33 μsec
)
In each notation: