This preview shows pages 1–2. Sign up to view the full content.
1
1
Algorithms
A Look At Efficiency
Counting Operations:
How much work is done?
1A
2
Algorithms
A computer program should be totally correct,
but it should also
execute as quickly as possible (timeefficiency)
use memory wisely (storageefficiency)
How do we compare programs (or algorithms in
general) with respect to execution time?
various computers run at different speeds due to
different processors
compilers optimize code before execution
the same algorithm can be written differently
depending on the programming paradigm
3
Analyzing Algorithms
Worst Case
Case with maximum number of operations
Best Case
Case with minimum number of operations
Average Case
Average number of operations over all
cases.
4
What are the operations?
Search an array for a value
public static int search(int[] x, int target)
{
for (int i = 0; i < x.length; i++)
{
if (x[i] == target) return i;
}
return 1;
}
1
2
3
4
5
6
5
Counting Operations
Let the x.length = n.
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.
 Spring '09
 ReidMiller
 Algorithms

Click to edit the document details