CS216: Program and Data Representation University of Virginia Computer Science Spring 2006 David Evans Lecture 2: Orders of Growth

Slides:



Advertisements
Similar presentations
Cs3102: Theory of Computation Class 22: Introducing Complexity Spring 2010 University of Virginia David Evans Exam 2: due now Read Chapter 7 (we skip Ch.
Advertisements

Intro to Analysis of Algorithms. Algorithm “A sequence of unambiguous instructions for solving a problem, i.e., for obtaining a required output for any.
 The running time of an algorithm as input size approaches infinity is called the asymptotic running time  We study different notations for asymptotic.
David Evans CS200: Computer Science University of Virginia Computer Science Lecture 16: Quicker Sorting.
CSE332: Data Abstractions Lecture 2: Math Review; Algorithm Analysis Tyler Robison Summer
CSE332: Data Abstractions Lecture 2: Math Review; Algorithm Analysis Dan Grossman Spring 2010.
Chapter 3 Growth of Functions
The Growth of Functions
Asymptotic Growth Rate
Cutler/HeadGrowth of Functions 1 Asymptotic Growth Rate.
David Evans CS150: Computer Science University of Virginia Computer Science Lecture 14: Asymptotic Growth.
CS3381 Des & Anal of Alg ( SemA) City Univ of HK / Dept of CS / Helena Wong 2. Analysis of Algorithms - 1 Analysis.
Tirgul 2 Asymptotic Analysis. Motivation: Suppose you want to evaluate two programs according to their run-time for inputs of size n. The first has run-time.
Elementary Data Structures and Algorithms
DATA STRUCTURES AND ALGORITHMS Lecture Notes 1 Prepared by İnanç TAHRALI.
CSE 373 Data Structures and Algorithms Lecture 4: Asymptotic Analysis II / Math Review.
Cs1120 Fall 2009 David Evans Lecture 19: Stateful Evaluation.
COMPSCI 102 Introduction to Discrete Mathematics.
MA/CSSE 473 Day 03 Asymptotics A Closer Look at Arithmetic With another student, try to write a precise, formal definition of “t(n) is in O(g(n))”
Algorithmic Complexity: Complexity Analysis of Time Complexity Complexities Nate the Great.
Program Performance & Asymptotic Notations CSE, POSTECH.
For Wednesday Read Weiss chapter 3, sections 1-5. This should be largely review. If you’re struggling with the C++ aspects, you may refer to Savitch, chapter.
SEARCHING, SORTING, AND ASYMPTOTIC COMPLEXITY Lecture 12 CS2110 – Fall 2009.
1 Computer Algorithms Lecture 3 Asymptotic Notation Some of these slides are courtesy of D. Plaisted, UNC and M. Nicolescu, UNR.
CS 221 Analysis of Algorithms Instructor: Don McLaughlin.
Asymptotic Analysis-Ch. 3
Week 12 - Wednesday.  What did we talk about last time?  Asymptotic notation.
Algorithms Growth of Functions. Some Notation NNatural numbers RReal numbers N + Positive natural numbers R + Positive real numbers R * Non-negative real.
Algorithm Analysis CS 400/600 – Data Structures. Algorithm Analysis2 Abstract Data Types Abstract Data Type (ADT): a definition for a data type solely.
CS216: Program and Data Representation University of Virginia Computer Science Spring 2006 David Evans Lecture 3: Levels of Abstraction
Class 21: Introducing Complexity David Evans cs302: Theory of Computation University of Virginia Computer Science.
CSE373: Data Structures and Algorithms Lecture 3: Math Review; Algorithm Analysis Nicki Dell Spring 2014.
Growth of Functions. 2 Analysis of Bubble Sort 3 Time Analysis – Best Case The array is already sorted – no swap operations are required.
Chapter 5 Algorithms (2) Introduction to CS 1 st Semester, 2015 Sanghyun Park.
CSC – 332 Data Structures Generics Analysis of Algorithms Dr. Curry Guinn.
Time Complexity of Algorithms (Asymptotic Notations)
CS 2601 Runtime Analysis Big O, Θ, some simple sums. (see section 1.2 for motivation) Notes, examples and code adapted from Data Structures and Other Objects.
Big-O. Algorithm Analysis Exact analysis: produce a function f(n) measuring how many basic steps are needed for a given inputs n On any input of size.
Analysis of Algorithm. Why Analysis? We need to know the “behavior” of algorithms – How much resource (time/space) does it use So that we know when to.
COP 3530 Spring2012 Data Structures & Algorithms Discussion Session Week 5.
1/6/20161 CS 3343: Analysis of Algorithms Lecture 2: Asymptotic Notations.
CS 206 Introduction to Computer Science II 01 / 30 / 2009 Instructor: Michael Eckmann.
David Evans Class 15: P vs. NP (Smiley Puzzles and Curing Cancer) CS150: Computer Science University of Virginia Computer.
CS216: Program and Data Representation University of Virginia Computer Science Spring 2006 David Evans Lecture 8: Crash Course in Computational Complexity.
Asymptotic Notation Faculty Name: Ruhi Fatima
1 Chapter 2 Algorithm Analysis All sections. 2 Complexity Analysis Measures efficiency (time and memory) of algorithms and programs –Can be used for the.
DR. Gatot F. Hertono, MSc. Design and Analysis of ALGORITHM (Session 2)
1 Section 5.6 Comparing Rates of Growth We often need to compare functions ƒ and g to see whether ƒ(n) and g(n) are about the same or whether one grows.
1 Chapter 2 Algorithm Analysis Reading: Chapter 2.
CSE373: Data Structures and Algorithms Lecture 3: Math Review; Algorithm Analysis Linda Shapiro Winter 2015.
Analysis of Algorithms CS 477/677 Instructor: Monica Nicolescu Lecture 2.
Chapter 2 Algorithm Analysis
Asymptotic Analysis.
Introduction to Algorithms
Analysis of Algorithms
Great Theoretical Ideas in Computer Science
Growth of functions CSC317.
The Growth of Functions
Introduction to Algorithms Analysis
Asymptotic Growth Rate
Asymptotic Analysis.
Chapter 2: Fundamentals of the Analysis of Algorithm Efficiency
Lecture 13: Cost of Sorts CS150: Computer Science
Advanced Analysis of Algorithms
Searching, Sorting, and Asymptotic Complexity
Algorithms Analysis Algorithm efficiency can be measured in terms of:
Limits: A Rigorous Approach
Introduction to Discrete Mathematics
Advanced Algorithms Analysis and Design
Estimating Algorithm Performance
Presentation transcript:

CS216: Program and Data Representation University of Virginia Computer Science Spring 2006 David Evans Lecture 2: Orders of Growth

2 UVa CS216 Spring Lecture 2: Orders of Growth Menu Predicting program properties Orders of Growth: O,  Course Survey Results Everyone should have received an 1.Informing you of your PS1 partner 2.Giving the section room locations 3.Explaining that PS1 is now due Monday, Jan 30

3 UVa CS216 Spring Lecture 2: Orders of Growth Predicting Program Properties

4 UVa CS216 Spring Lecture 2: Orders of Growth Cavalier Daily, Friday Jan 20 ( “We’ve tried to take steps to try and mitigate the problems by moving administrators off the system, making some improvements to the code,” Webb said. “Unfortunately, to see whether it works, students need to be on the system.”

5 UVa CS216 Spring Lecture 2: Orders of Growth Predicting Running Time Experimentally: measure how long the program takes on particular inputs –Generalize, extrapolate to other input sizes Analytically: figure out how the amount of work scales with the input size –Understand what the program does Need to combine with experimental results on some inputs and analytical understanding to make good predictions

6 UVa CS216 Spring Lecture 2: Orders of Growth Order Notation Four notations: O( f ),  ( f ), o( f ),  ( f ) These notations define sets of functions –Functions from positive integer to real When we say, “Algorithm A is O(n) ” we mean, running time of A  O (n) where n measures the input size to A.

7 UVa CS216 Spring Lecture 2: Orders of Growth Big O Intuition: the set O(f) is the set of functions that grow no faster than f –More formal definition coming soon Asymptotic growth rate –As input to f approaches infinity, how fast does value of f increase –Hence, only the fastest-growing term in f matters: O(n 3 )  O(12n 2 + n) O(n)  O(63n + log n – 423)

8 UVa CS216 Spring Lecture 2: Orders of Growth Examples O(n3)O(n3) O(n2)O(n2) f(n) = n 2.5 f(n) = 12n 2 + n f(n) = n 3.1 – n 2 Faster Growing

9 UVa CS216 Spring Lecture 2: Orders of Growth Formal Definition f  O (g) means: There are positive constants c and n 0 such that f(n)  cg(n) for all values n  n 0.

10 UVa CS216 Spring Lecture 2: Orders of Growth O Examples x  O (x 2 ) ? Yes, c = 1, n 0 =2 works fine. 10x  O (x) ? Yes, c = 11, n 0 =2 works fine. x 2  O (x) ? No, no matter what c and n 0 we pick, cx 2 > x for big enough x f (n)  O (g (n)) means: there are positive constants c and n 0 such that f(n)  cg(n) for all values n  n 0.

11 UVa CS216 Spring Lecture 2: Orders of Growth Question Given f  O (h) and g  O (h) which of these are true: a.For all positive integers m, f (m) < g (m). b.For some positive integer m, f (m) < g (m). c.For some positive integer m 0, and all positive integers m > m 0, f (m) < g (m). (left as problem for Exam 1)

12 UVa CS216 Spring Lecture 2: Orders of Growth a is false: Prove by Counter-Example a.For all positive integers m, f (m) < g (m). f (n)  O (h (n)) and g (n)  O (h (n)) f (n)  O (g (n)) means there are positive constants c and n 0 such that f(n)  cg(n) for all values n  n 0. Pick h (n) = n 2, f (n) = 5n 2, g(n)= n 3. For m = 2, f (m) = 20 > 8 = g(m). Therefore, a is false.

13 UVa CS216 Spring Lecture 2: Orders of Growth If f  O (h) and g  O (h) then, for some positive integer m, f (m) < g (m). g must grow faster than h, otherwise g would be in O(h). f must grow no faster than h, since f  O (h) So, if g grows faster than h, but f grows as slow or slower than h, eventually, g(n) > f (n) so for some m, f (m) < g (m). b is true: Intuition

14 UVa CS216 Spring Lecture 2: Orders of Growth If f  O (h) and g  O (h) then, for some positive integer m, f (m) < g (m). 1. f  O (h)  there are positive constants c and n 0 such that f(n)  ch(n) for all values n  n 0 2. g  O (h)  there are no positive constants c 1 and n 1 such that g(n)  c 1 h(n) for all values n  n 1. So, for all positive constants c 2, g(q)  c 2 h(q) for some value q. b: Proof by Contradiction

15 UVa CS216 Spring Lecture 2: Orders of Growth If f  O (h) and g  O (h) then, for some positive integer m, f (m) < g (m). Suppose statement is false. Then, for all positive k, f(k)  g(k) From (1),  c  n 0 such that  n > n 0, f(n)  ch(n) From (2),  c 1  n 1 such that  n > n 1, g(n) > c 1 h(n) Combining,  c  c 1  n 2 such that  n > n 2 ch(n) > c 1 h(n) b: Proof by Contradiction Note: n 2  max(n 0, n 1 ) This is a contradiction! Only works if c = infinity, but c must be a positive integer

16 UVa CS216 Spring Lecture 2: Orders of Growth Lower Bound:  (Omega) f(n) is  (g (n)) means: There are positive constants c and such that f (n)  cg(n) for all n  n 0. Difference from O – this was 

17 UVa CS216 Spring Lecture 2: Orders of Growth O(n3)O(n3) O(n2)O(n2) f(n) = n 2.5 f(n) = 12n 2 + n f(n) = n 3.1 – n 2 Where is  (n 2 ) ? (n2)(n2) Faster Growing

18 UVa CS216 Spring Lecture 2: Orders of Growth (n3)(n3) (n2)(n2) f(n) = n 2.5 f(n) = 12n 2 + n f(n) = n 3.1 – n 2 O(n2)O(n2) Slower Growing Inside-Out

19 UVa CS216 Spring Lecture 2: Orders of Growth Survey Results Summary See course web site for more detailed results

20 UVa CS216 Spring Lecture 2: Orders of Growth Honor Questions How much faith do you think we should put in the honor system for this class? –30 Should have complete trust in honor system –43 Enough to have take-home exams –6 A little, but don't trust take-home exams –1 Don't trust the students at all, need to police everything 73/80 Exam 1 will be take home

21 UVa CS216 Spring Lecture 2: Orders of Growth Honor Disadvantage? Do you feel you are at a disadvantage if you follow the course honor policy strictly? –69 no –11 yes I hope the majority answer here will help convince the 11 “yes” answered they are not really at a disadvantage. Long term, being honorable is never a disadvantage.

22 UVa CS216 Spring Lecture 2: Orders of Growth Honor Reporting If you observed a classmate cheating on a take-home exam, what would you do? 36 Report the student anonymously to the course staff 20 Confront the student 11 Report the student to the course staff 8 Nothing 3 Initiate an honor charge 2 No Selection Course Pledge disallows this now. If you can’t handle this, don’t sign the course pledge and take a different class.

23 UVa CS216 Spring Lecture 2: Orders of Growth Course Pledge Read this carefully – you are expected to know it and follow it Only pledge you need to sign this semester Requires: –No lying, cheating, or stealing –Helping your classmates learn –No toleration of dishonorable behavior –Helping the course staff improve the course

24 UVa CS216 Spring Lecture 2: Orders of Growth Programming Self-Rating –4 among best –26 above average –41 about average –8 a little below, far below The programming you will do in this class is different enough from what you have done previously, that you probably don’t really know. Everyone should be confident you will do well in this class. You don’t need to be a super code hacker to ace this class.

25 UVa CS216 Spring Lecture 2: Orders of Growth Programming Languages Python: –74 Not at all –6 Some familiarity Any assembly language: –72 Not at All –7 Some familiarity –1 Lots of experience Very few of you have experience with the language we use in this class (that is part of why we use them). You should not be worried about this!

26 UVa CS216 Spring Lecture 2: Orders of Growth Survey Results More results (as well as my answers to the questions you asked) are posted on the course web page

27 UVa CS216 Spring Lecture 2: Orders of Growth Charge Sections meet today and tomorrow –Order Notation practice –Recurrence Relations Wednesday: Levels of Abstraction, Introducing Lists –Read Chapter 3 in the textbook