0% found this document useful (0 votes)
50 views4 pages

Efficiencies: Best Case Minimum Time Required For Program Execution

The document discusses algorithm analysis notation. It provides examples of best case, average case, and worst case running times for linear search. It also defines big O, big Omega, and big Theta notations used to describe the upper bounds, lower bounds, and tight bounds of an algorithm's running time complexity.

Uploaded by

bumbleshet
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views4 pages

Efficiencies: Best Case Minimum Time Required For Program Execution

The document discusses algorithm analysis notation. It provides examples of best case, average case, and worst case running times for linear search. It also defines big O, big Omega, and big Theta notations used to describe the upper bounds, lower bounds, and tight bounds of an algorithm's running time complexity.

Uploaded by

bumbleshet
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Guaro Sidney F.

BSCS-2

Efficiencies:
Best Case Minimum time required for program execution.

Ex: Linear search:


Search a key k in a set A={a1,a2,a3,.an}
A={5,7,2,1,6,8,10,4,15,13,12,20,31,11,
17,25}
search(5);
int search (int k){
for(int i=1 to n){
if (A[i]==k)
return I;
}
return (-1); //NOT FOUND
}

Average Case Average time required for program execution.

Ex: Linear search: Solution: Search, beginning at the u elemt of an


Search a key k in a set A={a1,a2,a3,.an} array
A={5,7,2,1,6,8,10,4,15,13,12,20,31,11, search(25);
17,25} int search (int k){
search(4); for(int i=u to n){
int search (int k){ if (A[i]==k)
for(int i=1 to n){ return I;
if (A[i]==k) }
return I; return (-1); //NOT FOUND
} }
return (-1); //NOT FOUND }
}
Guaro Sidney F. BSCS-2

Worst Case Maximum time required for program execution.

Ex: Linear search: Soln: Search, beginning at the last element of


Search a key k in a set A={a1,a2,a3,.an} an array
A={5,7,2,1,6,8,10,4,15,13,12,20,31,11, search(25);
17,25} int search (int k){
search(25); for(int i=n to 1){
int search (int k){ if (A[i]==k)
for(int i=1 to n){ return I;
if (A[i]==k) }
return I; return (-1); //NOT FOUND
} }
return (-1); //NOT FOUND }
}
Guaro Sidney F. BSCS-2

Notation:
Big Oh Notation, - The (n) is the formal way to express the upper
bound of an algorithm's running time. It measures the worst case time
complexity or longest amount of time an algorithm can possibly take to
complete.

Asymptotic Notation 3
Example: n2 + n = O(n3)
Ex: Proof:
Here, we have f(n) = n2 + n, and g(n) =
n3
Notice that if n 1, n n3 is clear.
Also, notice that if n 1, n2 n3 is
clear.
Side Note: In general, if a b, then na
nb
whenever n 1. This fact is used often in
these
types of proofs.
Therefore,
n2 + n n3 + n3 = 2n3
We have just shown that
n2 + n 2n3 for all n 1
Thus, we have shown that n2 + n =
O(n3)
(by definition of Big-O, with n0 = 1, and c
= 2.)
Guaro Sidney F. BSCS-2

Omega Notation, - The (n) is the formal way to express the lower
bound of an algorithm's running time. It measures the best case time
complexity or best amount of time an algorithm can possibly take to
complete.
Example: n3 + 4n2 = (n2)
Proof:
Here, we have f(n) = n3 + 4n2,
Ex: and g(n) = n2
It is not too hard to see that if
n 0,
n3 n3 + 4n2
We have already seen that if n
1,
n2 n3
Thus when n 1,
n2 n3 n3 + 4n2
Therefore,
1n2 n3 + 4n2 for all n 1
Thus, we have shown that n3 +
4n2 = (n2)
(by definition of Big-, with n0 =
1, and c = 1.)

Theta Notation, - The (n) is the formal way to express both the
lower bound and upper bound of an algorithm's running time.

Ex:
Example: n2 + 5n + 7 = (n2)

Proof:

When n 1,

n2 + 5n + 7 n2 + 5n2 + 7n2
13n2

When n 0,

n2 n2 + 5n + 7

Thus, when n 1

1n2 n2 + 5n + 7 13n2

Thus, we have shown that n2 +


5n + 7 = (n2)

(by definition of Big- , with n0 =


1, c1 = 1, and

c2 = 13.)

You might also like