Está en la página 1de 9

Page 1

Mathematics
for
Algorithms
Page 2
Mathematical References
Sequences
Finite sequence where n = 1, 2, 3, 4, 5


Infinite sequence generates the
sequence


Observe that the general rule for the nth term
i.e. 2n is inserted as an element in the middle.
n a
n
2 =
10 ; 8 ; 6 ; 4 ; 2
5 4 3 2 1
= = = = = a a a a a
n a
n
2 =
, 2 , , 10 ; 8 ; 6 ; 4 ; 2
5 4 3 2 1
n a a a a a = = = = =
Page 3
Logarithms
x b
a
x
x
x y x
y x og
y
x
y x xy
x
b
b
a
b
y
b
b b b
b b b
a
=
=
=
=
|
|
.
|

\
|
+ =
log
log
log
log
log log
log 1 log
log log ) ( log
k k
n 2 2
1
< <

k n k < < log 1


Theorem: If k and n are positive
integers satisfying
Then
Theorem:
Page 4
Mathematical Induction
Using mathematical induction we can prove
that a collection of statements are true.
The statements are usually indexed by an integer
n. For example, the assertion that



Is true for all n, is an assertion about all n. i.e. an
infinitely many statements.
2
) 1 (
1
+
=

=
n n
i
n
i
Page 5
Mathematical Induction
In order to prove that a sequence of
statements s(1), s(2) , s(3) . are true
using mathematical statement we must
follow two steps.
Basic step : prove that statement s(1) is true
Inductive step: Assume that the nth statement
s(n) is true and use this assumption to prove
that statement s(n+1) is true.
Page 6
Example Proof by induction
Prove that

Basic step Show that the statement is true
for n =1. This would be the first of the infinitely
many statements.
Plug in n=1 into the question and see if it is true.




2
) 1 (
1
+
=

=
n n
i
n
i
1
2
) 1 1 ( 1
1
1
1
=
+
= =

= i
i Yes, it is true!
Page 7
Example proof by induction
Induction step: Suppose the equation is true for n, this
means that we assume that


Is true for n. And we will use it to prove that the next
consecutive statement i.e. (n+1)st statement is true as
well. State with the (n+1)st statement



2
) 1 (
1
+
=

=
n n
i
n
i
) 1 (
1
1
1
+ + =

=
+
=
n i i
n
i
n
i
2
) 2 )( 1 (
) 1 (
2
) 1 ( + +
= + +
+
=
n n
n
n n
Start with
the sum
2
) 2 )( 1 (
1
1
+ +
=

+
=
n n
i
n
i
Need to
show
Page 8
Analysis of Algorithms
Analysis of algorithms is the process of estimating the
running time and space (memory) utilization of an
algorithm as a function of the input size.

These estimates are also referred to as time and space
complexity of an algorithm.
The estimated time complexity is independent of the
machine the algorithm will run on.

This allows us to compare time complexity of
different algorithms.

Page 9
Best case, worst case and average case time
complexity
Among all inputs of size n the one that takes the least
amount of time to run produces the best case time
complexity.

Similarly the input of size n that takes the longest to run
will produce the worst case time complexity for an
algorithm. We will mostly be interested in worst case
running time of algorithms.

Average case time complexity is obtained by finding the
time complexity of all input classes of size n and finding
their average. Often very complicated to find

También podría gustarte