Professional Documents
Culture Documents
• Complexity
© of Algorithms
by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sixth Edition, Mc Graw-Hill, 2011
© by Kenneth H. Rosen, Discrete Mathematics & its
Algorithms (3.1)
• Some Applications:
– Internet security
CSE 504,© by Kenneth H. Rosen, Discrete Mathematics & its Applications,
2 Seventh Edition, Mc Graw-Hill, 2011
Algorithms (3.1) (cont.)
• Introduction
– Methodology:
– Definition:
Pseudocode:
CSE 504,© by Kenneth H. Rosen,intermediate step between
6 Seventh
Discrete Mathematics & its Applications, an 2011
Edition, Mc Graw-Hill,
Algorithms (3.1) (cont.)
• Searching Algorithms
• Sorting
– Goal:
3 2 2 2 2 2 2 2 1
2 3 3 3 3 3 1 1 2
4 4 4 1 1 1 3 3 3
1 1 1 4 4 4 4 4 4
5 5 5 5 5 5 5 5 5
1st pass 2nd pass 3rd pass 4th pass
= ordered = permute
CSE 504,© by Kenneth H. Rosen, Discrete Mathematics & its Applications,
15 Seventh Edition, Mc Graw-Hill, 2011
Algorithms (3.1) (cont.)
• Greedy algorithms
Therefore:
• Lemma:
– Note:
• Choose k
• Choose C; it may depend on your choice of k
• Once you choose k and C, you must prove the truth of
the implication (often by induction)
CSE 504,© by Kenneth H. Rosen, Discrete Mathematics & its Applications,
24 Seventh Edition, Mc Graw-Hill, 2011
The Growth of functions (3.2) (cont.)
– Definition:
f(n)
if lim 0 then f is o(g) (called little - o of g)
n g ( n )
– Example: 3n + 5 is O(n2)
3n of5limits, it's easy to show
Proof: Using the theory
lim 0 2
n n
complexity class.
– Theorem:
– Example:
Solution:
This means to simplify the expression.
Throw out stuff which you know doesn't grow as
fast.
We are using the property that if f is O(g) then f+g
is
O(g).
CSE 504,© by Kenneth H. Rosen, Discrete Mathematics & its Applications,
32 Seventh Edition, Mc Graw-Hill, 2011
The Growth of functions (3.2) (cont.)
– Solution (cont.)
• a minute?
• a day?
• a year?
– Example:
Suppose
Algorithm 1 has complexity n2 - n + 1
Algorithm 2 has complexity n2/2 + 3n +2
Hence we write
Algorithm 1 has complexity n2 + O(n)
Algorithm 2 has complexity n2/2 + O(n)
• Time Complexity
– Basic operations:
procedure (n, c, A, B)
/* A (and B) are upper triangular */
for i from 1 to n do
for j from i to n do
B(i, j) = cA(i, j)
end do
end do
Quadratic
CSE 504,© bycomplexity but
Kenneth H. Rosen, Discrete the& itsleading
Mathematics
41 coefficient
Applications, Seventh Edition, Mc Graw-Hill, is
2011
Complexity of Algorithms (3.3) (cont.)
Total:
(n - 1)+ (n - 2) + . . . . + 1 = O(n2) or quadratic complexity
CSE 504,© by Kenneth H. Rosen, Discrete Mathematics & its Applications,
44 Seventh Edition, Mc Graw-Hill, 2011
Complexity of Algorithms (3.3) (cont.)
Total:
O(n2) + O(n) = O(n2)
CSE 504,© by Kenneth H. Rosen, Discrete Mathematics & its Applications,
46 Seventh Edition, Mc Graw-Hill, 2011
Chapter 3 (Part 2):
The Fundamentals: Algorithms, the
Integers & Matrices
© by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sixth Edition, Mc Graw-Hill, 2011
© by Kenneth H. Rosen, Discrete Mathematics & its
• Introduction
– Definition 1:
4 | 12 4 18
– Definition 2:
Q.E.D.
CSE 504,© by Kenneth H. Rosen, Discrete Mathematics & its Applications,
56 Seventh Edition, Mc Graw-Hill, 2011
– Theorem 4:
– Theorem 6:
– Theorem 8
1. Hashing Functions
2. Pseudorandom Numbers
a) Encryption:
• Mathematical expression:
f(p) = (p + 3) mod 26 0 p 25