mathematical preliminaries the factorial function permutations logarithms summations recurrence...

8
Mathematical Preliminaries • The Factorial Function • Permutations • Logarithms • Summations • Recurrence Relations • Algorithm Analysis

Upload: antonia-lloyd

Post on 01-Jan-2016

214 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Mathematical Preliminaries The Factorial Function Permutations Logarithms Summations Recurrence Relations Algorithm Analysis

Mathematical Preliminaries

• The Factorial Function

• Permutations

• Logarithms

• Summations

• Recurrence Relations

• Algorithm Analysis

Page 2: Mathematical Preliminaries The Factorial Function Permutations Logarithms Summations Recurrence Relations Algorithm Analysis

The Factorial Function

Definition:

Stirling’s approximation:

n!=1⋅2 ⋅3⋅L ⋅(n −1) ⋅n

n!≈ 2πn ( ne )n

Page 3: Mathematical Preliminaries The Factorial Function Permutations Logarithms Summations Recurrence Relations Algorithm Analysis

Permutations

• A permutation of a sequence is the members of a sequence arranged in some order.

• There are n! different permutations for a sequence with n distinct members.

• To generate a permutation of an array:

void permute(int *a, int n) { for (int i = n; i > 0; i--) swap(a[i - 1], a[random(i)]); }

Page 4: Mathematical Preliminaries The Factorial Function Permutations Logarithms Summations Recurrence Relations Algorithm Analysis

Logarithms

logb y = x ⇔ bx = y ⇔ blogb y = y

lognm = logn + logm

logn

m= logn − logm

logn r = r logn

loga n =logb n

logb a

Page 5: Mathematical Preliminaries The Factorial Function Permutations Logarithms Summations Recurrence Relations Algorithm Analysis

Summations

f (i) = f (1) + f (2) +L + f (n −1) + f (n)i=1

n

i =n(n +1)

2i=1

n

i2 =2n3 + 3n2 + n

6i=1

n

n = n logni=1

logn

ai =an+1 −1

a−1i= 0

n

∑ for a >1

Page 6: Mathematical Preliminaries The Factorial Function Permutations Logarithms Summations Recurrence Relations Algorithm Analysis

Recurrence Relations

• For the factorial function:

• For the Fibonacci sequence:

n!= n ⋅(n −1)!, 1!= 0!=1

Fib(n) = Fib(n −1) + Fib(n − 2), Fib(1) = Fib(2) =1

Page 7: Mathematical Preliminaries The Factorial Function Permutations Logarithms Summations Recurrence Relations Algorithm Analysis

Algorithm Analysis• The time T to run an algorithm as a function of n is

written as T(n)• T(n) is in the set O(f(n)) if there are two positive

constants c and n0 such that

• If the upper bound (highest growth rate) for an algorithm is f(n) then it is in O(f(n)) in the worst case

• For all inputs that are large enough, the algorithm always executes in less time than

T(n)≤ c f (n) for all n > n0

c f (n)

Page 8: Mathematical Preliminaries The Factorial Function Permutations Logarithms Summations Recurrence Relations Algorithm Analysis

Comparison of Running Timesin Increasing Order

O(1)O(log n)O(n)O(n log n)O(nc)O(cn)