Class 19: Analyzing Algorithms
-
Upload
david-evans -
Category
Technology
-
view
295 -
download
0
description
Transcript of Class 19: Analyzing Algorithms
Class 19: Analyzing Algorithms
cs1120 Fall 2011David Evans5 October 2011
2
Plan
Asymptotic Operators RecapAnalyzing biggerHow Bletchley Park Really Broke Lorenz
(maybe not until Friday)
Assistant Coaches’ Review Sessions for Exam 1:Tuesday (tomorrow), 6:30pm, Rice 442
Wednesday, 7:30pm, Rice 442
3
XOR MachineA B
FALSE
TRUE
TRUE
Design by Alex Shin
4
XOR Machine
NOT from book
FloatWine
Design by Anthony Teate
FloatWine
WineFloatWine
5
XOR Machine
NOT from book
FloatWine
Design by Anthony Teate
FloatWine
WineFloatWineFloatWine
WineWine
6
Measuring Cost
Machines vary, so we want to understand how the cost to execute a procedure scales with the size of the input
We use the asymptotic operators to abstract away all the details
7
Recap• Big-O: functions that grow no faster than f
• Omega (): functions that grow no slower than f
• Theta (): functions that grow as fast as f
8
Example
Prove: 73n2 + n (n2)
9
Real CSists
Proofs are Not Scary!
• Theorem: There exists a polygon with four sides.
• Proof:
What kind of proof is this?
Proof by Construction
We can prove a “there exists an X with property Y” theorem, by showing an X that has property Y
O(f) means “there are positive constants c and n0 such that g(n) cf(n) for all n n0
So, to prove g is in O(f) we need to find c and n0 and show that g(n) cf(n) for all n n0
Dis-Proof by Construction
• To prove g is not in O(f):• O(f) means: there are positive constants c and n0 such that g(n) cf(n) for all n n0
• So, to prove g is not in O(f) we need to find a way given any c and n0, to find an n n0 such that g(n) > cf(n).
13
Example
Prove: 73n2 + n (n2)
14
Algorithm Analysis
What is the asymptotic running time of the Scheme procedure below:
(define (bigger a b) (if (> a b) a b))
15
Algorithm Analysis
What is the asymptotic running time of (> a b):
(define (bigger a b) (if (> a b) a b))
16
What are we really measuring?
Input size: number of tape squares it takes to write down the input
Running time: number of steps it takes before TM enters a final state
Input size for (bigger a b) = nNumber of tape squares to represent input (not its
magnitude)
Why doesn’t the alphabet size matter?
17
18
Next Class
What if the input is binary instead of unary?
a>b# 0# if a > b, 1# if a bwhere a, b are the numbers a, b
represented in binary