Lecture 16 Complexity of Functions CSCI – 1900 Mathematics for Computer Science Fall 2014 Bill Pine.

Slides:



Advertisements
Similar presentations
TWO STEP EQUATIONS 1. SOLVE FOR X 2. DO THE ADDITION STEP FIRST
Advertisements

한양대학교 정보보호 및 알고리즘 연구실 이재준 담당교수님 : 박희진 교수님
2. Getting Started Heejin Park College of Information and Communications Hanyang University.
Data Structures Through C
BY Lecturer: Aisha Dawood. The notations we use to describe the asymptotic running time of an algorithm are defined in terms of functions whose domains.
Analysis of Computer Algorithms
By D. Fisher Geometric Transformations. Reflection, Rotation, or Translation 1.
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
0 - 0.
ALGEBRAIC EXPRESSIONS
DIVIDING INTEGERS 1. IF THE SIGNS ARE THE SAME THE ANSWER IS POSITIVE 2. IF THE SIGNS ARE DIFFERENT THE ANSWER IS NEGATIVE.
MULTIPLYING MONOMIALS TIMES POLYNOMIALS (DISTRIBUTIVE PROPERTY)
ADDING INTEGERS 1. POS. + POS. = POS. 2. NEG. + NEG. = NEG. 3. POS. + NEG. OR NEG. + POS. SUBTRACT TAKE SIGN OF BIGGER ABSOLUTE VALUE.
SUBTRACTING INTEGERS 1. CHANGE THE SUBTRACTION SIGN TO ADDITION
MULT. INTEGERS 1. IF THE SIGNS ARE THE SAME THE ANSWER IS POSITIVE 2. IF THE SIGNS ARE DIFFERENT THE ANSWER IS NEGATIVE.
Addition Facts
Lecture 11: Algorithms and Time Complexity I Discrete Mathematical Structures: Theory and Applications.
22C:19 Discrete Math Algorithms and Complexity
Recurrences : 1 Chapter 3. Growth of function Chapter 4. Recurrences.
© S Haughton more than 3?
Linking Verb? Action Verb or. Question 1 Define the term: action verb.
Energy & Green Urbanism Markku Lappalainen Aalto University.
Lets play bingo!!. Calculate: MEAN Calculate: MEDIAN
Designed and Presented by Dr. Ayman Elshenawy Elsefy Dept. of Systems & Computer Eng.. Al-Azhar University
Past Tense Probe. Past Tense Probe Past Tense Probe – Practice 1.
Chapter 5 Test Review Sections 5-1 through 5-4.
Algorithm Complexity Level II, Term ii CSE – 243 Md. Monjur-ul-hasan
Addition 1’s to 20.
25 seconds left…...
Test B, 100 Subtraction Facts
Chapter Algorithms 3.2 The Growth of Functions
© 2006 Pearson Addison-Wesley. All rights reserved10 A-1 Chapter 10 Algorithm Efficiency and Sorting.
Week 1.
Complexity Analysis (Part II)
We will resume in: 25 Minutes.
18-Dec-14 Pruning. 2 Exponential growth How many leaves are there in a complete binary tree of depth N? This is easy to demonstrate: Count “going left”
Lecture 12 Permutations and Combinations CSCI – 1900 Mathematics for Computer Science Fall 2014 Bill Pine.
Lecture 15 Functions CSCI – 1900 Mathematics for Computer Science Fall 2014 Bill Pine.
Lecture 11 Mathematical Induction CSCI – 1900 Mathematics for Computer Science Fall 2014 Bill Pine.
Lecture 20 Finite State Machines CSCI – 1900 Mathematics for Computer Science Fall 2014 Bill Pine.
Lecture 13 Elements of Probability CSCI – 1900 Mathematics for Computer Science Fall 2014 Bill Pine.
Foundations of Data Structures Practical Session #11 Sort properties, Quicksort algorithm.
12-Apr-15 Analysis of Algorithms. 2 Time and space To analyze an algorithm means: developing a formula for predicting how fast an algorithm is, based.
CSE115/ENGR160 Discrete Mathematics 03/01/12
Introduction to Algorithms Rabie A. Ramadan rabieramadan.org 2 Some of the sides are exported from different sources.
Cutler/HeadGrowth of Functions 1 Asymptotic Growth Rate.
1 Data Structures A program solves a problem. A program solves a problem. A solution consists of: A solution consists of:  a way to organize the data.
CS 206 Introduction to Computer Science II 01 / 28 / 2009 Instructor: Michael Eckmann.
Asymptotic Notations Iterative Algorithms and their analysis
Time Complexity Dr. Jicheng Fu Department of Computer Science University of Central Oklahoma.
1 Big-Oh Notation CS 105 Introduction to Data Structures and Algorithms.
CSC 201 Analysis and Design of Algorithms Lecture 04: CSC 201 Analysis and Design of Algorithms Lecture 04: Time complexity analysis in form of Big-Oh.
1 Chapter 1 Analysis Basics. 2 Chapter Outline What is analysis? What to count and consider Mathematical background Rates of growth Tournament method.
Starting Out with C++ Early Objects Seventh Edition by Tony Gaddis, Judy Walters, and Godfrey Muganda Modified for use by MSU Dept. of Computer Science.
Chapter 5 Algorithms (2) Introduction to CS 1 st Semester, 2015 Sanghyun Park.
Java Methods Big-O Analysis of Algorithms Object-Oriented Programming
Time Complexity of Algorithms
CS 206 Introduction to Computer Science II 09 / 18 / 2009 Instructor: Michael Eckmann.
Prof. Amr Goneid, AUC1 Analysis & Design of Algorithms (CSCE 321) Prof. Amr Goneid Department of Computer Science, AUC Part 1. Complexity Bounds.
تصميم وتحليل الخوارزميات عال311 Chapter 3 Growth of Functions
CS 150: Analysis of Algorithms. Goals for this Unit Begin a focus on data structures and algorithms Understand the nature of the performance of algorithms.
Searching Topics Sequential Search Binary Search.
Lecture 19 Minimal Spanning Trees CSCI – 1900 Mathematics for Computer Science Fall 2014 Bill Pine.
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI Dale Roberts, Lecturer Computer Science, IUPUI
Introduction to Algorithms
Sorting by Tammy Bailey
Efficiency (Chapter 2).
Analysis of Algorithms
Presentation transcript:

Lecture 16 Complexity of Functions CSCI – 1900 Mathematics for Computer Science Fall 2014 Bill Pine

CSCI 1900 Lecture Lecture Introduction Reading –Rosen Sections 3.2, 3.3 Examine some functions occurring frequently in Computer Science Characterize the efficiency of an algorithm –Big-Oh –Big-Theta

CSCI 1900 Lecture Functions in CS mod n function – f n ( m ) = m mod n –Example f 3 ( 7 ) = 1f 3 ( 8 ) = 2f 3 ( 111 ) = 0 Factorial function –f ( n ) = n!n! = n* (n-1)! –f ( 0 ) = 1f ( 1 ) = 1f ( 2 ) = 2f ( 3 ) = 6 f ( 10 )> 10 6 f ( 20 )>10 18 f (70) >

CSCI 1900 Lecture Functions in CS (cont) Floor function –f ( x ) = largest integer ≤ x f (2.1) = 2 f (2.9) = 2 f ( ) = 2 f (3) = 3 f (-2.3) = -3Nota Bene: -2 > -2.3

CSCI 1900 Lecture Functions in CS (cont) Ceiling function –f( x ) =smallest integer ≥ x f( ) = 3 f( 2.9 ) = 3 f( ) = 3 f( 3 ) = 3 f( ) = 4 f( -2.3 ) = -2Nota Bene: -2 > -2.3

CSCI 1900 Lecture Functions in CS (cont) Exponential –f ( x )=2 x f ( 1 )=2 f ( 2 )=4 f ( 2.2 )=4.4957… f ( 0 )=1 f ( -1 )=1/2 f ( -2 )=1/4

CSCI 1900 Lecture Functions in CS (cont) Logarithm –f n ( x )=log n (x) the power to which n must be raised to yield x f 2 ( 4 ) = 2 f 2 ( 8 ) = 3 f 2 ( 2 ) = 1 f 2 ( 1 ) = 0 f 2 ( 1/2 ) = -1 f 2 ( 1/16 ) = -4 f 2 ( 0 ) = undefined

Growth of Functions CSCI 1900 Lecture

CSCI 1900 Lecture Growth of Functions (cont) Previous example show that functions grow at different rates Specifically, let: f (x) = x, g(x) = 2 x –f (1) = 1, g(1) = 2 – f (10) = 10, but g (10) = 1024 Polynomial functions –n « n 2 « n 2.2 « n 3

CSCI 1900 Lecture Growth of Functions (cont) All log functions grow at the same rate, regardless of the base –log 2 ( n ) grows at the same rate as log 100 ( n ) –We usually write log 2 as lg –Recall log n ( k ) = log m ( k ) / log m ( n ) Powers of the log function –(log n ) « (log n) 2 « (log n) 304 « n

CSCI 1900 Lecture Growth of Functions (cont) log compared to polynomials –lg n « n « n lg( n ) « n ( lg( n ) ) 2 « n (lg( n )) 1670 « n 2 Polynomials compare to exponentials –n 2 « n 3 « n 2876 « 2 n Exponentials compared to factorial – 2 n « n!

CSCI 1900 Lecture Growth of Functions (cont) In general, the classes of functions, in order of increasing running time are –constant « log( n ) « n « n log( n ) « n 2 « n 3 « … « 2 n « n!

CSCI 1900 Lecture Big-Oh Notation f  O( g ) if there exist two constants, c and n 0 such that | f (n) |  c | g(n) | for all n  n 0 –This means: f grows no faster than g does What is in O(n 3 )? –Anything that grows no faster than n 3 –f ( n ) = 10n 3 –f ( n ) = n n 2 – n –f ( n ) = n 2 –f ( n ) = n lg n –f ( n ) = lg n –f ( n ) = 2

CSCI 1900 Lecture Big-Oh Example Show that n n  O( n 3 ) Need to find a c and n 0 such that c n 3 > n n 2 – n for all n > n 0 Two important consequences of f  O( g ) –g serves as an upper bound on f –We ignore the behavior for small values of n

CSCI 1900 Lecture Big-Theta Notation f   ( g ), if f and g have same order – f  O( g ) and g  O( f ) What is in  ( n 3 ) –f ( n ) = n n 2 – n is in  ( n 3 ) –f ( n ) = 2 is not in  ( n 3 ) –f ( n ) = n 2 is not in  ( n 3 ) –f ( n ) = lg n is not in  ( n 3 ) –f ( n ) = n lg n is not in  ( n 3 )

CSCI 1900 Lecture Running Time The  -class of a function that describes the number of steps performed by an algorithm is called the running time of the algorithm This allows us to compare algorithms for a specific task For example: –bubble sort   ( n 2 ) –quicksort   ( n lg n) –What is the fastest running-time for a comparison-based sorting algorithm?

CSCI 1900 Lecture Determining Running Time To compare two algorithm’s running times –Select an operation that is central to the algorithm For searching, we might choose comparison For sorting, we might choose comparison or perhaps data saving –Examine the algorithm to determine how the count of the key operation depends upon “input size” To evaluate a single algorithm –Count the total number of operations –Examine the algorithm to determine how the count of the key operation depends upon “input size”

CSCI 1900 Lecture Running Time Example Consider the following function function meanOf( n ) sum  0 for i = 1 thru n sum  sum + i mean = sum / n return mean

CSCI 1900 Lecture Running Time Example (cont) What is the input size? Identify and count the characterizing operation –Number of pre-loop operations –Number of operations in the loop –Number of post-loop operations What is the running time? Is there a more efficient way to determine meanOf ?

CSCI 1900 Lecture Key Concepts Summary Examined some functions “useful” in Computer Science Characterize the efficiency of an algorithm –Big-Oh –Big-Theta Reading for next time –Kolman Sections 7.1, 7.2