Computer Science 112 Spring 2015
Gregory M. Kapfhammer
Introduction to Computer Science II
Keep in touch!Office Hours, Email, Web, Twitter
Algorithms
Correctness
Performance
How fast is an algorithm?
Try some examples!
for loops
Constant
Linear
Quadratic
Cubic
git pull
CLASSPATH
Compile
Run!
Results?
Conclusions?
Algorithm
Function
Draw a Graph
Slow growing
Fast
Fast growing
Slow
Function Exploration
Add in exponential
Add in factorial
Plot the functions
Create a table of values
Fastest Growth?
Slowest Growth?
Conclusions?
Implications?
Take a step back
Limitations of empirical studies
Direct Comparison
Limited Inputs
Fully Implemented
Characterize programs as functions of input size
Hands-on Example
Largest Integer?
Largest Double?
How did you determine?
Computing Sums
Correct?
Incorrect?
Conduct an Experiment
Efficient?
Inefficient?
Why?
Pseudo code
When n gets big
Revisit computing sums
Best, Worst, Average
Worst-Case Graph
f(n) is O(g(n))
f(n) is O(g(n))
f(n) is O(g(n))
f(n) is O(g(n))
Does this really matter?
Composing Long Strings
String concatenation
git pull
Which is faster?
repeat1 vs. repeat2
Why?
Additional examples
ArrayMax
ArrayFind
Worst-Case time complexity?
Why?
Run an experiment
Analysis confirmed?