This preview shows pages 1–2. Sign up to view the full content.
Asymptotic Notation
goal:
To simplify analysis by getting rid of unneeded info.
 It also tells us how an algorithm scales up;
that is:
how it behaves with large inputs
example:
Execution time of an algorithm: 0.00001 * n^2 + 10n + 1000 = O(n^2)
Special Classes of Algorithms
O(1)
= constant time, basic operations
O(n)
= linear time, sequential searches, traversals
O(log n)
= logarithmic time, binary searches, balanced trees
O(nlog
n)
= no term, best sorting algorithms
O(n^2)
= quadratic time, bubble sort
O(n^k)
= polynomial time
O(a^n)
=
exponential time, npcomplete problems(traveling salesman, chess games)
... best solved by heuristic behaviors
example:
Obtain the complexity (asymptotic notation) of obtaining the maximum of
an array of numbers.
algorithm: arrayMax(int A[], int n);
input:
A > an integer array
n> array length
# of
execution
s
:
public int
arrayMax(
int
A[],
int
n) {
1
int
currentMax = A[0];
1
int
i;
n1
for
(i=1; i < n ;i++) {
n1
if
(currentMax <
a[i]) {
x < n1
currentMax = A[i];
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
This is the end of the preview. Sign up
to
access the rest of the document.
 Fall '08
 Staff
 Data Structures

Click to edit the document details