day05

day05 - CS1: Introduction to Computation Day 5: October 13,...

Info iconThis preview shows pages 1–15. Sign up to view the full content.

View Full Document Right Arrow Icon
Caltech CS 1 -- Fall 2008 CS1: Introduction to Computation Day 5: October 13, 2008 Computational Complexity
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Caltech CS 1 -- Fall 2008 This is Spinal Tap (1984)
Background image of page 2
Caltech CS 1 -- Fall 2008 Nigel Tufnel's problem • Doesn't understand the way a function (the volume of his amplifier, V ) scales with the size of its inputs: pk : the position of the knob (0-11) pow : the power rating of the amplifier He thinks V(pk, pow) = k 1 * pk In reality: V(pk, pow) = k 1 * pk * pow (ignoring nonlinearities)
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Caltech CS 1 -- Fall 2008 Last time • Described different classes of computations: – linear recursive – linear iterative – tree recursive • in terms of – how computations unfold in space and time – pending operations
Background image of page 4
Caltech CS 1 -- Fall 2008 Today • How do we quantify the resources (time, space) that our procedures require? • How do these resource requirements change with the size of the inputs?
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Caltech CS 1 -- Fall 2008 Time complexity • What we care about most is – How does the run time grow with input size? e.g. • sum-integers , ifib grew linearly • fib grew exponentially – How can we quantify this?
Background image of page 6
Caltech CS 1 -- Fall 2008 Being precise • Recall: (define (sum-integers n) (if (= n 0) 0 (+ n (sum-integers (- n 1))))) time = (n+1) * (T cmp + T if + 2*T add + T call )
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Caltech CS 1 -- Fall 2008 Not being too precise… time = (n+1) * (T cmp + T if + 2*T add + T call ) More simply: time = C 1 + n*C 2 C 1 and C 2 are constant factors • How does the run time scale as n gets larger?
Background image of page 8
Caltech CS 1 -- Fall 2008 Doing the numbers time = C 1 + n*C 2 Let’s say C 1 = 1000 , C 2 = 10 • n = 0 time = 1000 • n = 1 time = 1010 • n = 10 time = 1100 • n = 1000 time = 11000 • n = 10 6 time = 10001000 Conclusion: C 2 dominates C 1 for large n
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Caltech CS 1 -- Fall 2008 Doing the numbers time = C 1 + n*C 2 • Run time is linear in n For large n , C 2 is all that really counts C 1 has little effect • How to express this mathematically?
Background image of page 10
Caltech CS 1 -- Fall 2008 “Big O” notation • A function g(n) is O( f(n) ) if for all n greater than some n 0 – then g(n) <= C * f(n) • for some constant C i.e. g(n) grows no faster than f(n) for sufficiently large n • This is just math, not programming
Background image of page 11

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Caltech CS 1 -- Fall 2008 Example of big O • Let g(n) = 100 * n 2 + 50 * n + 2000 <= 150 * n 2 for large enough n • So g(n) is O(n 2 ) –here, C = 150 –note: C = 100.00001 would also work
Background image of page 12
Caltech CS 1 -- Fall 2008 0 3750 7500 11250 15000 0 2.5 5.0 7.5 10.0 100 n^2 + 50 n + 2000 150 n^2
Background image of page 13

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
A tighter bound… • g(n) = 100 * n 2 + 50 * n + 2000 g(n) is O(n 2 ) but g(n) is also O(n 3 ) ! g(n) <= n
Background image of page 14
Image of page 15
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 09/25/2010 for the course CS 1 taught by Professor Chang during the Spring '08 term at UMBC.

Page1 / 79

day05 - CS1: Introduction to Computation Day 5: October 13,...

This preview shows document pages 1 - 15. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online