Mathematical Foundation. CSE 6331 Algorithms Steve Lai

Similar documents
Ch3. Asymptotic Notation

Test One (Answer Key)

CS 270 Algorithms. Oliver Kullmann. Growth of Functions. Divide-and- Conquer Min-Max- Problem. Tutorial. Reading from CLRS for week 2

Advanced Course of Algorithm Design and Analysis

Sums, products and sequences

ITEC 360 Data Structures and Analysis of Algorithms Spring for n 1

CS161 Handout 05 Summer 2013 July 10, 2013 Mathematical Terms and Identities

Recurrence Relations

Model of Computation and Runtime Analysis

Algorithm Analysis. Algorithms that are equally correct can vary in their utilization of computational resources

CS583 Lecture 02. Jana Kosecka. some materials here are based on E. Demaine, D. Luebke slides

Infinite Sequences and Series

COMP26120: More on the Complexity of Recursive Programs (2018/19) Lucas Cordeiro

Model of Computation and Runtime Analysis

CS / MCS 401 Homework 3 grader solutions

Classification of problem & problem solving strategies. classification of time complexities (linear, logarithmic etc)

Trial division, Pollard s p 1, Pollard s ρ, and Fermat s method. Christopher Koch 1. April 8, 2014

A recurrence equation is just a recursive function definition. It defines a function at one input in terms of its value on smaller inputs.

JANE PROFESSOR WW Prob Lib1 Summer 2000

CS166 Handout 02 Spring 2018 April 3, 2018 Mathematical Terms and Identities

10.1 Sequences. n term. We will deal a. a n or a n n. ( 1) n ( 1) n 1 2 ( 1) a =, 0 0,,,,, ln n. n an 2. n term.

Fundamental Algorithms

Recursive Algorithms. Recurrences. Recursive Algorithms Analysis

Sequences, Mathematical Induction, and Recursion. CSE 2353 Discrete Computational Structures Spring 2018

MA131 - Analysis 1. Workbook 9 Series III

Mathematics review for CSCI 303 Spring Department of Computer Science College of William & Mary Robert Michael Lewis

MAT1026 Calculus II Basic Convergence Tests for Series

CS:3330 (Prof. Pemmaraju ): Assignment #1 Solutions. (b) For n = 3, we will have 3 men and 3 women with preferences as follows: m 1 : w 3 > w 1 > w 2

4.3 Growth Rates of Solutions to Recurrences

A New Solution Method for the Finite-Horizon Discrete-Time EOQ Problem

This Lecture. Divide and Conquer. Merge Sort: Algorithm. Merge Sort Algorithm. MergeSort (Example) - 1. MergeSort (Example) - 2

Algorithms and Data Structures Lecture IV

Chapter 22 Developing Efficient Algorithms

Read carefully the instructions on the answer book and make sure that the particulars required are entered on each answer book.

Problems with Solutions in the Analysis of Algorithms. Minko Markov

Once we have a sequence of numbers, the next thing to do is to sum them up. Given a sequence (a n ) n=1

d) If the sequence of partial sums converges to a limit L, we say that the series converges and its

Lecture 3: Asymptotic Analysis + Recurrences

Lecture 10: Mathematical Preliminaries

Introduction to Algorithms 6.046J/18.401J LECTURE 3 Divide and conquer Binary search Powering a number Fibonacci numbers Matrix multiplication

MA131 - Analysis 1. Workbook 2 Sequences I

Topics. Homework Problems. MATH 301 Introduction to Analysis Chapter Four Sequences. 1. Definition of convergence of sequences.

INEQUALITIES BJORN POONEN

Solutions to Math 347 Practice Problems for the final

CSE Introduction to Parallel Processing. Chapter 3. Parallel Algorithm Complexity

6.3 Testing Series With Positive Terms

Math 4107: Abstract Algebra I Fall Webwork Assignment1-Groups (5 parts/problems) Solutions are on Webwork.

Chapter 2. Asymptotic Notation

Sequences A sequence of numbers is a function whose domain is the positive integers. We can see that the sequence

Chapter 0. Review of set theory. 0.1 Sets

MATH 324 Summer 2006 Elementary Number Theory Solutions to Assignment 2 Due: Thursday July 27, 2006

Sequences I. Chapter Introduction

and each factor on the right is clearly greater than 1. which is a contradiction, so n must be prime.

Ma 530 Introduction to Power Series

Chapter 6 Infinite Series

Analysis of Algorithms. Introduction. Contents

Divide & Conquer. Divide-and-conquer algorithms. Conventional product of polynomials. Conventional product of polynomials.

COMP285 Midterm Exam Department of Mathematics

Convergence of random variables. (telegram style notes) P.J.C. Spreij

IP Reference guide for integer programming formulations.

CS161 Design and Analysis of Algorithms. Administrative

A sequence of numbers is a function whose domain is the positive integers. We can see that the sequence

Sequences. Notation. Convergence of a Sequence

sin(n) + 2 cos(2n) n 3/2 3 sin(n) 2cos(2n) n 3/2 a n =

In number theory we will generally be working with integers, though occasionally fractions and irrationals will come into play.

Data Structures and Algorithm. Xiaoqing Zheng

M17 MAT25-21 HOMEWORK 5 SOLUTIONS

The Growth of Functions. Theoretical Supplement

Design and Analysis of Algorithms

University of Manitoba, Mathletics 2009

Exam 2 CMSC 203 Fall 2009 Name SOLUTION KEY Show All Work! 1. (16 points) Circle T if the corresponding statement is True or F if it is False.

Sequences, Series, and All That

Math 2112 Solutions Assignment 5

Math 140A Elementary Analysis Homework Questions 3-1

Matriculation number: You have 90 minutes to complete the exam of InformatikIIb. The following rules apply:

OPTIMAL ALGORITHMS -- SUPPLEMENTAL NOTES

MA131 - Analysis 1. Workbook 3 Sequences II

CS 332: Algorithms. Linear-Time Sorting. Order statistics. Slide credit: David Luebke (Virginia)

CSI 5163 (95.573) ALGORITHM ANALYSIS AND DESIGN

(A sequence also can be thought of as the list of function values attained for a function f :ℵ X, where f (n) = x n for n 1.) x 1 x N +k x N +4 x 3

Design and Analysis of ALGORITHM (Topic 2)

MATH 21 SECTION NOTES

Math 609/597: Cryptography 1

2.4 - Sequences and Series

Chapter 9: Numerical Differentiation

Inverse Matrix. A meaning that matrix B is an inverse of matrix A.

CIS 121 Data Structures and Algorithms with Java Spring Code Snippets and Recurrences Monday, February 4/Tuesday, February 5

62. Power series Definition 16. (Power series) Given a sequence {c n }, the series. c n x n = c 0 + c 1 x + c 2 x 2 + c 3 x 3 +

CSE 1400 Applied Discrete Mathematics Number Theory and Proofs

Math 113 Exam 4 Practice

Algorithms Design & Analysis. Divide & Conquer

1 Generating functions for balls in boxes

CHAPTER 10 INFINITE SEQUENCES AND SERIES

Skip Lists. Presentation for use with the textbook, Algorithm Design and Applications, by M. T. Goodrich and R. Tamassia, Wiley, 2015 S 3 S S 1

MAS111 Convergence and Continuity

The Boolean Ring of Intervals

De Moivre s Theorem - ALL

Solutions to Tutorial 5 (Week 6)

MA131 - Analysis 1. Workbook 7 Series I

Seunghee Ye Ma 8: Week 5 Oct 28

Transcription:

Mathematical Foudatio CSE 6331 Algorithms Steve Lai

Complexity of Algorithms Aalysis of algorithm: to predict the ruig time required by a algorithm. Elemetary operatios: arithmetic & boolea operatios: +,,, /, mod, div, ad, or compariso: if a < b, if a = b, etc. brachig: go to assigmet: ad so o a b

The ruig time of a algorithm is the umber of elemetary operatios required for the algorithm. It depeds o the size of the iput ad the data themselves. The worst-case time coml p exity of a algorithm is a fuctio of the iput size : T ( ) = the worst case ruig time over all istaces of size. The worst-case asymptotic time complexity is the worst case time complexity expressed i O, Ω, or Θ. The word asymptotic is ofte omitted. 3

O-Notatio Note: Uless otherwise stated, all fuctios cosidered i this class are assumed to be oegative. Covetioal Defiitio : We say f( ) = Og ( ( )) or f ( ) is O( g( )) if the re exist positive costats c ad such that f ( ) cg( ) for all. 0 0 More Abstract Defiitio: f( ): f( ) = O( g( )) i the Og ( ( )) =, covetioal meaig i.e., the set of all fuctio s that are O( g( )) i the covetioal meaig. 4

These expressios all mea the same thig: 4 + 3 = O ( ) 4 + 3 is O ( ) 4 + 3 O ( ) 4 3 is i ( ). + O Sometimes Og ( ( )) is used to mea some fuctio i the set Og ( ( )) which we do't care to specify. Example: we may write: Let f( ) = 3 + O(log ). 5

Theorem 1 If f( ) = Og ( ( )) ad f( ) = Og ( ( )), the 1 1 1. f ( ) + f ( ) = O( g ( ) + g ( )) 1 1. f ( ) + f ( ) = O(max( g ( ), g ( ))) 1 1 3. f ( ) f ( ) = O( g ( ) g ( )) 1 1 Proof. There exist positive costats c, c such that 1 1 1 1 1 1 1 f ( ) c g ( ) ad f ( ) c g ( ) for sufficietly large. Thus, f( ) + f ( ) cg( ) + cg ( ) ( c + c ) ( g ( ) + g ( )) 1 1 ( c + c ) max( g ( ), g ( )). 1 1 By defiitio, 1 ad hold. 3 ca be proved similarly. 6

Ω-Notatio Covetioal Defiitio: We say f( ) = Ω ( g ( )) if there exist positive costats c ad 0 such that f ( ) cg( ) for all. Or defie Ω ( g( )) as a set: Ω ( g( ) ) 0 f( ): f( ) = Ω ( g( )) i the = covetioal meaig Theorem : If f1( ) =Ω ( g1( )) ad f( ) =Ω( g( )), the 1. f1( ) + f( ) = Ω ( g1( ) + g( )). f1( ) + f( ) = Ω (max( g1( ), g( ))) 3. f ( ) f ( ) = Ω ( g ( ) g ( )) 1 1 7

Θ-Notatio Covetioal Defiitio: We say f( ) = Θ( g ( )) if there exist positive costats c, c, ad such that 1 0 cg 1 ( ) f( ) cg ( ) for all 0. That is, f( ) = Θ( g( )) [ f( ) = Og ( ( )) ad f( ) = Ω ( g ( ))]. I terms of sets: Θ( g ( )) = Og ( ( )) Ω ( g( )) Theorem 3: If f ( ) =Θ ( g ( )) ad f ( ) =Θ( g ( )), the 1 1 1. f ( ) + f ( ) = Θ ( g ( ) + g ( )). 1 1 f ( ) + f ( ) 1 = Θ(max( g ( ), g ( ))) 1 1 1 3. f ( ) f ( ) = Θ( g ( ) g ( )) 8

o-notatio, ω-notatio Defiitio of o f( ) f( ) = og ( ( )) iff lim = 0. g ( ) Defiitio of ω f( ) f( ) = ω( g ( )) iff lim =. g ( ) 9

Some Properties of Asymptotic Notatio Trasitive property: If f( ) = Og ( ( )) ad g ( ) = Oh ( ( )), the f( ) = Oh ( ( )). The trasitive property also holds for Ω ad Θ. f( ) = Og ( ( )) g ( ) =Ω( f( )). See the textbook for may others. 10

Asymptotic Notatio with Multiple Parameters Defiitio: We say that f ( m, ) = Ogm ( (, )) iff there are positive costats c, m, such that 0 0 f( m, ) cg( m, ) for all m m ad. Agai, we ca defie Ogm ( (, )) as a set. 0 0 Ω( gm (, )) ad Θ( gm (, )) ca be similarly defied. 11

Coditioal Asymptotic Notatio Let P ( ) be a predicate. We write iff there exist positive costats c, such that T ( ) cf( ) for all for which P ( ) is true. 0 T ( ) = O( f( ) P ( )) 0 Ca similarly defie Ω( f( ) P ( )) ad Θ( f ( ) P ( )). Example: Suppose for 0, T ( ) + = 3 if is odd 4 if is eve = Θ The, T ( ) ( is eve) 1

Smooth Fuctios A fuctio f( ) is smooth odecreasig ad f( ) = O( f( )). iff f( ) is asymptotically Thus, a smooth fuctio does ot grow very fast. Example: log, log, are all smooth. What about? 13

Theorem 4. If f( ) is smooth, the f( b) = O( f( )) for ay fixed positive iteger b. Proof. By iductio o b. Iductio base: For Iductio hypothesis: where b >. b = 1,, obviously f ( b) = O( f ( )). ( ) Assume f ( b 1) = O( f( )), Iductio step: Need to show f ( b) = O( f ( )). We have: ( ( 1) ) ( (( 1) )) ( ) ( ) f ( b) f b = O f b O( f ( )) (i.e., f( b) f ( b 1) c f ( b 1) cc f( ) for some 1 1 1 costats c, c ad sufficietly large ). The theorem is proved. 14

Theorem 5. If T ( ) = Of ( ( ) a power of b), where b is a costat, T ( ) is asymptotically odecreasig ad f( ) is smooth, the T ( ) = Of ( ( )). Proof. From the give coditios, we kow: 1. T ( ) is asymptotically odecreasig.. T ( ) cf( ) for sufficietly large ad a power of b. 1 3. f ( b) c f ( ) for sufficietly large. k k 1 For ay, there is a such that. k b < b + Whe is sufficietly large, we have T( ) T( b ) c f( b ) cc f( b ) cc f( ). k+ 1 k+ 1 k 1 1 1 Be defiitio, T ( ) = Of ( ( )). 15

c 1 k k 1 b b + T T b c ( ) c ( ) cc f ). k + 1 k+ 1 k ( ) ( ) 1f b 1c f b 1 ( 16

Theorem 6. b If T( ) = Ω ( f( ) a power of b), where is a costat, T( ) is asymptotically odecreasig ad f( ) is smooth, the T( ) = Ω ( f( )). Theorem 7. b If T( ) = Θ ( f( ) a power of b), where is a costat, T( ) is asymptotically odecreasig ad f( ) is smooth, the T( ) = Θ( f( )). Applicatio. I order to show T ( ) = O ( log ), we oly have to establish T ( ) O ( log a power of ), provided that T( ) is asymptotically odecreasi g. 17

Some Notatios, Fuctios, Formulas x x = the floor of x. = the ceilig of x. log = log. (Or lg ) 1 ( 1) ( ). + + + = + = Θ k k For costats k > 0, 1+ + 3 + + k+ 1 ( ). + 1 + 1 1 a a 1 If 1, the 1. a + a+ a + + a = = 1 a a 1 If a> 1, the f( ) = 1 + a+ a + + a = Θ( a ). If 1, the ( ) 1 (1). a< f = + a+ a + + a =Θ k = Θ 18

Approximatig summatios by itegratio Suppose fuctio m f is icreasig or decreasig. f ( x) dx f ( i) f ( x) dx + m i= m ( ) f x dx m ( ) f x dx m f( ) f icreasig f( m) f dereasig ( ) m So, if f is icreasig ad f ( x) dx = Ω f ( ), the i= m f () i = Θ ( ) ( ) Similarly, if f is decreasig ad f ( x) dx = Ω f ( m), the i= m f () i = Θ ( ) 1 1 Example: =Θ dx l l m lg lg m m =Θ =Θ i= mi x m ( ) ( ) 19

Aalysis of Algorithm: Example Procedure BiarySearch( A, x, i, j) if i m > j the retur(0) ( i+ j) case Am [ ] = x: retur( m) ( ) ( A x i m ) Am [ ] < x: retur BiarySearch( A, x, m+ 1, j) Am [ ] ed > x: retur BiarySearch(,,, 1) 0

Aalysis of Biary Search Let T( ) deote the worst-case ruig time. T( ) satisfies the recurrece: T( ) = T. + c Solvig the recurrece yields: T( ) = Θ(log ) 1

Euclid's Algorithm Fid gcd( ab, ) for itegers ab, 0, ot both zero. Theorem: If b= 0, gcd( ab, ) = a. fuctio Euclid( ab, ) if b = 0 the else If b> 0, gcd( ab, ) = gcd( ba, mod b) retur( a) ( ba b) retur Euclid(, mod ) The ruig time is proportioal to the umber of recursive calls.

Aalysis of Euclid's Algorithm a b c = a mod b 0 0 0 0 0 a b c = a mod b 1 1 1 1 1 a b c a b Observe that a = b = c. k k 1 k W.l.o.g., assume a b. The values a, a, a, decrease by at least oe half 0 0 0 4 Reaso: If c: = a mod b, the c< a. So, there are most O(log a 0 with each recursive call. ) recursive calls. 3

Solutio to Q4 of example aalysis 0 1 log i=,,,, i log k= 0 k= 0 log k log ( k ) ( ) ( = = = ) Θ =Θ =Θ ( ) log ( 4 ) 4