Understand efficiency of programs
Separate time and space efficiency of a program
Challenges
Evaluate efficiency
Timing a program
Timing programs is inconsistent
GOAL to evaluate diff. algorithms
Running time
-(time varies for different inputs, but cannot really express a relationship between inputs and time!)
+ varies between algorithms
Which operations to count
Assumes steps take constant time
Counting operations, better but…
GOAL to evaluate different algorithms
Counting operations
+(count varies for diff. inputs and can come up with a relationship between inputs and the count)
+ depends on algorithm
- depends on implementation
- independent of computers
+ no real def. of which operations to count
Needs a better way
what we HAVE
* timing evaluates machines
what we WANT
Need to which input to use
Different inputs
Best case
min. running time
- constant
- first element of any list
Average case
avg. running time
- practical measure
Worst case
max. running time
- linear in length of list
- must search entire list
Orders of Growth - goal
Input is very big
Want to evaluate programs efficiency when input is very big
Growth of program’s run time
Want to express program’s run time as input grows
Upper bound
Want to put an upper bound on growth
“order of” not “exact”
Do not need to be precise “order of” not “exact” growth
Largest factor
We will look at largest factor in run time
Types of orders of growth
- constant \+ linear - quadratic - logarithmic \+ n log n - exponential
Measuring Order of Growth
Big Oh Notation