discrete mathematics transparency no. 2-1 chapter 2. basic structures: sets, functions, sequences...
TRANSCRIPT
Discrete Mathematics
Transparency No. 2-1
Chapter 2. Basic structures:
Sets, Functions, Sequences and Sums
Cheng-Chia Chen
The Foundations
Transparency No. 2-2
2.1 Sets
Basic structure upon which all other (discrete and continuous ) structures are built.
A set is a collection of objects. An object is anything of interest, maybe itself a
set.Definition 1.
A set is a collection of objects. The objects in a set are called the elements or
members of the set. If x is a member of a set S, we say S contains x. notation: x S vs x S
Ex: In 1,2,3,4,5, the collection of 1,3 5 is a set.
The Foundations
Transparency No. 2-3
Set descriptionHow to describe a set:?1. List all its member.
the set of all positive odd integer < 10 = ? The set all decimal digits = ? the set of all upper case English letters = ? The set of all nonnegative integers = ?
2. Set builder notation: P(x) : a property (or a propositional function) about
objects. e.g., P(x) = “ x > 0 and x is odd” then {x | P(x) } is the set of objects satisfying
property P. P(3) is true => 3 {x | P(x)} P(2) is false => 2 {x | P(x)}
The Foundations
Transparency No. 2-4
Conventions
N =def {x | x is a natural numbers } = { 0,1,2,3,...}
N+ =def {1,2,3,...}
Z =def {...,-3,-2,-1,0,1,2,3,...}
R =def the set of real numbers.
Problem:
The same set may have many different descriptions. {x | 0 < x <10 /\ x is odd } {1,3,5,7,9}, {5,3,1,9,7} {9,7,1,3,5}.
The Foundations
Transparency No. 2-5
Set predicatesDefinition 2.
Two sets S1, S2 are equal iff they have the same elements
S1 = S2 iff x (x S1 <-> x S2)Ex: {1,3,5} = {1,5,3} = {1,1,3,3, 5}Graphical representation of sets:
Venn Diagrams: rectangle: Universal set: U circles: sets points: particular elements point x inside circle S => x S point x outside S => x S.
S
S2
x
z
w
y
U
The Foundations
Transparency No. 2-6
Set predicates (cont’d)Null set ={} = =def the collection of no objects.Def 3’: [empty set] for-all x, x.Def 3. [subset]
A B iff all elements of A are elements of B. A B x (x A x B)).
Def 3’’: A B =def A B /\ A B.Exercise : Show that:
1. For all set A, (Pf: Let x be any element => x(By def) => x x ⇒
A holds. Hence x (x x ⇒ A) and 2. (A B /\ B A) (A = B) 3. A ⇒
Diagram representation of the set inclusion relationship.
The Foundations
Transparency No. 2-7
Size(or cardinality) of a finite set
An important property about sets is the number of members each set has. Such property is called its size or cardinality.
Def. 4: A: a set. Then |A| = the size(or cardinality) of set A = number of distinct elements in A.
Ex: |{1,3,3,5}| = 3 |{}| = 0 the set of decimal digits } | =|{0,1,..,9}| = 10
But how about |A| if A is not finite ? |N| = ? ; |Z| = ? ; |{2i | i N} | = ? ; |R| = ?∈ See section 2.4
The Foundations
Transparency No. 2-8
The power set
Def 6. If A is a set, then the collection of all subsets
of A is also a set, called the power set of A and is denoted as P(A) or 2A.
Ex: P({0,1,2}) = ? P({}) = ? |P({1,2,..., n})| = ?
Elements in a set are not ordered. But sometimes we need to distinguish between (1,3,4) and (3,4,1) --> ordered n-tuples
The Foundations
Transparency No. 2-9
Cartesian Products
Def. 7 [n-tuple] If a1,a2,...,an (n > 0) are n objects, then
“(a1,a2,...,an)” is a new object, called an (ordered) n-tuple [ with ai as its ith element. ]
Any ordered 2-tuple is called a pair.
Def. Two tuples (a1,a2,...,am) = (b1,b2,...,bn) iff (1) m = n and (2) ai = bi for all 1 ≤ i ≤ m.
The Foundations
Transparency No. 2-10
Cartesian product
Def. 8: [Cartesian product] A, B : two sets.
A x B =def {(a,b) | a A and b B } ∈ ∈
A1 x A2 x ...x An =def {(a1,...,an) | ai A∈ i for all 1 ≤ i ≤ n}.
Note: AxB can be simply written as AB.
Ex: A = {1,2}, B = {a,b,c} , C = {0,1}
1. A x B = ? ; 2. B x A = ?
3. A x {} = ? ; 4. A x B x C = ?
Def. 8.1: Any subset of AB is called a relation from A to B.
Problems: 1. when will A x B = B x A ?
2. |A x B | = ?
The Foundations
Transparency No. 2-11
2.2 Set operations
Union, intersection,difference , complement,Definition. If A and B are two sets from a
universe U, then 1. A B = {x | x A or x B }∈ ∈ 2. A B = {x | x A and x B }∈ ∈ 3. If A B = {} => call A and B disjoint. 4. A - B = {x | x A but x ∈ ∉ B } 5. ~ A = U – A = {x| x U but x∈ ∉A} = {x| x∉A} Venn diagram representationsEx: U = {1,..,10}, A = { 1,2,3,5,8} B = {2,4,6,8,10}=> A B , A B , A - B , ~ A = ?
The Foundations
Transparency No. 2-12
Set identities (page 124, 6th edition)
Identity laws: A {} = A ; A U ⋂ = ADomination law: U A = A ; {} A⋂ = {}Idempotent law: A ⋂A = A ; AA = Acomplementation: ~~A = A
commutative : A⋂B = B ⋂A ; AB=BAAssociative: A⋂(B⋂C) = (A⋂B)⋂C; ___?_____Distributive: A (B ⋂ C) = ? ; ____?_____De Morgan laws: ~(AUB) = _?_ ; ~(A ⋂ B)= ~A U ~BAbsorption law : A(A ⋂ B) = A; A ⋂ (AB) = AComplement law: A~A = U; A⋂~A = {}
The Foundations
Transparency No. 2-13
Prove set equality1. Prove that ~(A B) = ~A ~B by showing that
1.1 ~(A B)~A ~B and 1.2 ~A ~B ~(A B)
Pf. of 1 by definition and logic reasoning. It suffices to show that x. x~(AUB) iff x(~A ~B). Let x be any element. Then
x ~(AUB)
iff ~(xAUB) -- def. of complement
iff ~(xA \/ xB) -- def. of Union
iff (x A /\ x B) -- de Morgan law
iff (x ~A /\ x ~B) – def. of comlpement
iff x ~A ~B . -- def of intersection
Note that the top-down reading of the above proves 1.1 while the buttom-up reading proves 1.2.
The Foundations
Transparency No. 2-14
2. The previous set equality can also be proven
by using set builder and logical equivalence.
Pf:
~(AUB)
= {x | ~(xAUB) } -- def. of complement
= {x | ~(xA \/ xB) } -- def. of union
= {x | ~(xA) /\ ~(xB) } -- de Morgan law
= {x | (x~A) /\ (x~B)} -- def. of compement
= {x | x (~A~B) } -- def. of intersection
= ~A ~B. -- set builder notation :
{x|xC} = C
The Foundations
Transparency No. 2-15
Membership Table
3. Show distributive law : A U (B ⋂ C) = (AUB) ⋂ (AUC) by using membership table.
Let x be any element. Then we need only consider 8 cases as to whether x is a member of A or B or C. In all cases, we find that x A U (B C) iff x⋂ (AUB) (AUC) . Hence the equality holds.⋂
x A x B x C xAUB
xAUC
xB⋂C
xA U (B ⋂ C)
x(AUB)⋂(AUC)
0 0 0 0 0 0 0 0
0 0 1 0 1 0 0 0
0 1 0 1 0 0 0 0
0 1 1 1 1 1 1 1
1 0 0 1 1 0 1 1
1 0 1 1 1 0 1 1
1 1 0 1 1 0 1 1
1 1 1 1 1 1 1 1
The Foundations
Transparency No. 2-16
Set equality reasoning
4 show ~(A (B C)) = (~C ~B) ~A by set identities.
pf:
~(A (B C))
= ~A C ) -- de Morgan law
= C ) ~A -- commutative law
= (~B ~C) ~A -- de Morgan law
= (~C ~B) ~A -- commutative law
The Foundations
Transparency No. 2-17
Generalized set operations
Def. 6: Let A1,A2,...An: n sets and B = {A1,A2,...An }
12n{i=1,..n} Ai =def {x|xA for some AB}.
12n{i=1,..n} Ai=def {x| xA for all AB }.
Note: If B = {}, then = {} and U (why ?)Venn diagram representation of 123
and123Example:
123 = ?123
The Foundations
Transparency No. 2-18
Set representation (in computer)
Ordered (or Unordered) list/array union, intersection, ~: time consuming.
Balanced–tree representation; HashtableBit string:
U = {a1,...,an} is the universal set.
A: any subset of U A can be represented by the string:
s(A) = x1 x2 x3....xn , where
xi = (ai A ? 1 : 0) for all i = 1..n.∈ fast set operations suitable only if U is not large. constant size representation.
The Foundations
Transparency No. 2-19
2.3 FunctionsDef. 1 [functions] A, B: two sets
1. a partial function f from A to B is a set of pairs (x, y) AxB∈ s.t., for each x A there is at most one y B s.t. (x,y) f.∈ ∈ ∈ 2. f is a (total) function if for for each x A there is exactly one∈ y B with (x,y) f. ∈ ∈ Note if not specified otherwise, all
functions are assumed to be total. 3. if (x,y) f, we write f(x) = y.∈ 4. f : A B means f is a total function (or mapping) from A to B.
Def. 2. If f:A B then 1. A is the domain of f; 2. B is the codomain of f. If f(a)=b => 3. b is the image of a 4. a is the preimage of b 5. range(f) = f(A) = { f(x) | x A }.
The Foundations
Transparency No. 2-20
Types of functionsDef 4. f : A B ; S: a subset of A,
T: a subset of B
1. f(S) =def { y B | x S with f(x) = y }
2. f-1(T) =def { x A | y T with f(x) = y }
Def 5,7,8. [1-1(injection), onto(surjection), bijection]
f: A -> B. f is 1-1 (an injection) iff xyA. (xyf(x) f(y) ). f is onto (surjective, a surjection) iff yBxA f(x) = y. If f is 1-1 & onto, then f is said to be bijective (a
bijection, 1-1 correspondence)
The Foundations
Transparency No. 2-21
Properties of functions
1. If there is an onto mapping from A to B, then there is a 1-1 mapping from B to A.
2. If there is a 1-1 mapping from A to B then there is an onto mapping from B to A.
3. The onto (≥ ) and the 1-1(≤ ) relations between sets are reflexive and transitive (i.e., a preorder).
4. If there is a 1-1 mapping from A to B and a 1-1 mapping from B to A, then there is a 1-1 and onto mapping from A to B.
pf: (1) Let f:AB an onto. For each b B, let g(b) = {x A | f(x) = b} ≠ ∈ ∈∅ the function h:B⇒ A defined by h(b) = any x g(b) is 1-1. ∈
(2) f: A B a 1-1 mapping, b: any element in A. Then define g:B A with g(y) = (y = f(x) for some x A)? x : b). g is an onto. ∈
(3) is easy to verify. (4) is hard but understandable (reference).
The Foundations
Transparency No. 2-22
Real valued functionsF:A B is a real valued function iff A and B are subsets
of R.f1,f2: real valued functions
=> 1. (f1+f2) (x) = f1(x) + f2(x)
2. (f1• f2) (x) = f1(x) x f2(x).
3. f is increasing iff ?
x y implies f(x) f(y)
4. f is strictly increasing iff ?
x > y implies f(x) > f(y) ceiling(.), floor(.): R Z.
x = least integer x; y = greatest integer y Ex: 3.4 = 4; -3.4 = -3 ; 2 = 2 ; ; -3.4 = -4
The Foundations
Transparency No. 2-23
Operations on functions
A, B, C: any sets ; f: A B; g: B C, then
1. [identity function]
idA : A A s.t. idA(x) = x for all x in A.
2. [composition of g and f]
gf: A C s.t. (gf)(x) = g(f(x)) for x in A.
3. [inverse] If f is a bijection, then
f-1: B A s.t. f-1(y) = x iff f(x) = y for y in B. Graphical representations
The Foundations
Transparency No. 2-24
Properties of operations on functionsf: A B. g: B C; h: C D, then
1. f idA = f = idB f
2. h(g f) = (h g)f --- assoc.
3. (g f)-1 = f-1 g-1
If f: A B is a bijection then
4. f-1 f = idA and f f-1 = idB .
The Foundations
Transparency No. 2-25
2.4 Sequences and Summations
Sequences: a discrete structure used to represent an ordered list.
Let [n] = [1,n] = {1,2,…,n}. A sequence 1,2,… n of length n with value from a set B is called a finite B-sequence (of length n). Formally, a finite B-sequence (of length n) is a function : [n] B.
A(k) or ak where k [n] is called a term( 項 ) of the sequence. We use the notation {an} where an is a function (or
expression) of n to represent a sequence.A B-sequence is a function : N B.A general C indexed B-sequence is a function: f:CB.
The Foundations
Transparency No. 2-26
Summations
If {ak} is a sequence of length l, then we use
mjn ai or jm..n ai
to represent am + am+1 + … + an
If m(lower limit) = 1 and n(upper limit) = l =>ai =def a1 + a2+...al+ (...)
Summation rules :a + (a+d) + (a+2d)+... = ?a + ar +arr + ... = ?
The Foundations
Transparency No. 2-27
Summation rules
1. a + (a+d) + (a+2d)+... (a + (n-1) d ) = ?2. a + ar +arr + ... + a rn-1 = ?Sol 1: Let S = a + (a+d) + (a+2d)+... (a + (n-1)d).Then S = (a + (n-1)d) + (a+(n-2)d) +… (a+d)+a 2S = (2a + (n-1)d) + …. (2a+ nd) = (2a+ nd) x n.
=> S = [a + (n-1)d]n/2 = (a1 + an)n/2.Sol 2: Let S = a + ar + ar2+... +a r (n-1).Then rS = ar + ar2 + ar3 +… arn
(1-r)S = a - arn. => S = a(1-rn)/(1-r). If |r| < 1, then limitn S = a/(1-r) Some facts: (proofs using induction left as exercises!)
k=1..n k = n(n+1) / 2 ; k=1..nk2 = n(n+1)(2n+1)/6 k=1..n k3 = n2(n+1)2 /4
The Foundations
Transparency No. 2-28
cardinality of finite or infinite sets
Def. 4: |A| = the cardinality of set A = number of distinct elements in A.
Ex: |{1,3,3,5}| = 3 |{}| = 0But how about |A| if A is not finite ?
Ex: |N| = ? ; |Z| = ? ; | {2i | i N} | = ? |R| = ?∈Def. 4’: Two sets are said to have the same cardinality iff
there is a 1-1 & onto mapping between them. The collection of all sets which have the same cardinality is
said to be a cardinal number. Every non-negative integer n can be viewed as an
equivalence to the collection of all sets which has size n.
Def. 5: A set A is said to be finite iff |A| is a natural number; o/w it is infinite.
The Foundations
Transparency No. 2-29
countability of sets
Def. A set A is said to be denumerable (or coutably
infinite) iff |A| = |N| ( = aleph0). A set is countable iff either |A| = n for some n in
N or |A| = |N|.Exercises: Show that
1. |N| = |Z | = | Q+ | = |{x | x N and x >3 }| 2. |R| = | (-1, 1) | = |(0,1)| 3. |(0,1)| is uncountable
By exercise 1,2,3, R is not countable. Q+ and Z is countable.
p/q 1 2 3 4 …
1 1/1 1/2 1/3 1/4 …
2 2/1 2/2 2/3 2/4 …
3 3/1 3/2 3/3 3/4 …
4 4/1 4/2 4/3 4/4 …
… … … … … 5/5
How to enumerate Q+
The Foundations
Transparency No. 2-30
Properties of countable sets A is countable iff there is a onto mapping from N to A.Pf. “=>” If A is finite, obviously there is a onto mapping from N to A.
If A is denumerable, by definition, there is also a onto (&1-1)
mapping from N to A.
“<=“ If A is finite, it is surely countable.
If A is infinite, let f:N A be the surjection from N to A.
we can define a bijection g: N A from f as follows:
g(0) = f(0),
g(k) = f(j) where j = least {m | f(m){g(0), g(1),…,g(k-1)} for k >0.
Ex: If f: N A is then
g: N A is
As a result, |A| = |N| and is countable.Corollary: A is countable iff there is a 1-1 mapping from A to N.
5 3 5 1 3 2 1 1 4 …
5 3 1 2 4 …
The Foundations
Transparency No. 2-31
Properties of countable setsSuppose A B. Then
1. If B is countable, then A is countable.
2. If A is uncountable, then B is uncountable.
Pf: Note (2) is logically equivalent to (1) and hence is implied by (1).
(Pf of 1) Obviously A is countable if B is finite or A is finite.
If both B and A are infinite. Since B is denumerable, there is a 1-1 mapping f: B N. now define f’: A N with f’(x) = f(x) for all x A. Then f’ is also a 1-1 from A to N. Hence A is countable.
Corollaries: Every subset of a countable set is countable.
Since Q is countable (because |Q+| = |Q| why? ), all its subsets (Z, N, Even, {x | x > 10} …) are countable.
Every superset of a uncountable set is uncountable. Since (0,1) is uncountable, R is uncountable.
The Foundations
Transparency No. 2-32
Some uncoutable sets
0 1 2 3 4 ... f(0) 1 0 0 f(1) 0 0 f(2) 0 f(3) 0 0 1 0 0 f(4) 0 0 ... 0 0 0 1 1
Theorem: The set 2N is uncountable.
pf: Suppose 2N is denumerable. Thenthere is a bijection f: N -> 2N. I.e., 2N = {f(0),f(1),f(2),...} . Now consider the diagonal set
= { k N | k f(k) }. Since kf(k) iff k for all k, f(k) for all k.but since is a subset of N, by assumption, must equal to f(k) forsome k. This is a contradiction!
The Foundations
Transparency No. 2-33
|A| ≠ |2A|
Pf: (1) The case that A is finite is trivial since |2A| = 2|A| > |A| and there is no bijection b/t two finite sets with different sizes.
(2) Assume |A| = |2A|, i.e., there is a bijection f: A B, where B is 2A and f(A) = { f(x) | x A } = B.
Now define the so-called diagonal set in terms of f as follows:
= {x A | x ∈ f(x) }. Now (*) is a subset of A and (**) f(x) for any x A :∈ ( since x ∈ iff x f(x) for each x A. )∈ ==> is not a subset of A ( f is onto to 2∵ A), This is a contradiction to (*). Hence f must not exist!!
The Foundations
Transparency No. 2-34
Real set (0,1) is not countable
Theorem: The real set (0,1) is uncountable.pf: If n is a real in (0,1), then it can be represented as an infinite sequence n = 0.n1n2n3… where each nk is one of {0,…,9}.Ex: 0 = 0.00000 ; 1 = 0.9999… ½ = 0.500000… = 0.49999…. 1/3 = 0.3333… -3 = 0.14159….For the representation to be unique, we exclude any sequence of the form: 0.d1d2…dk9999…. and say any sequence not in such form a normal sequence. Now suppose the set (0,1) is denumerable. Then there must exist a bijection f: N (0,1).
The Foundations
Transparency No. 2-35
We apply diagonalization principle to define a number d from f as follows:
let d = 0.d0d1d2…. where
dk = (s == 0)? 8 : 9 – s,
where s=f(k)k is the kth digit of the fraction part of f(k)
digit f(n) 0 1 2 3 4 ... f(0)= .1 0 5 0 0 0 f(1)= . 0 2 0 f(2)= . 5 7 f(3)= . 0 0 7 0 0 …
d= .8 8 4 2 . .
The Foundations
Transparency No. 2-36
Now it can be shown that d is a normal sequence representing a real number in (0,1)
since it contains no 9. d f(n) for all n since by construction dn f(n)n, where
f(n)k is the kth digit of the fraction part of f(n).
This contradicts the facts that d (0,1) and f(N) = ∈(0,1).
The Foundations
Transparency No. 2-37
The Halting Problem (Section 3.1, 6th edition; p176)L : any of your favorite programming languages (C,
C++, Java, BASIC, etc. )Problem: write an L-program HALT(P,X), which takes
another L-program P(-) and string X as input, and
HALT(P,X) returns true if P(X) halts and
returns false if P(X) does not halt.
P(X) Halt ?
yes true
nofalse
Pr(x:String) {…..
}
P
“It’s a test …”
X
HALT(P,X)
Program you are asked to
design
The Foundations
Transparency No. 2-38
How hard is it to predict if a program will halt ?
Consider the 3n+1 programint f( int n ) {
if ( n == 1 ) return 1 ;
if (n % 2 == 0 ) { // n is even n/2
f(n % 2) ;
} else { // n is odd 3n+1
f( n*3 + 1) ;
}}
It is conjectured that f(n) halts (returns 1) for all n ≥ 1.
Ex: f(10) 5 16 8 4 2 1 (halts)
The Foundations
Transparency No. 2-39
Halt(P,X) does not exist Ideas leading to the proof:Problem1 : What about the truth value of the sentence:
L: L is false Problem 2 : Let S = {X | X X}. Then does S belong to S or not ?The analysis: S S => S S; S S => S S.
Problem 3 : 矛盾說 : 1. 我的矛無盾不穿 2. 我的盾可抵擋所有茅 結論 : 1. 2. 不可同時為真。
Problem 4 : 萬能上帝 : 萬能上帝無所不能 => 可創造一個不服從他的子民 => 萬能上帝無法使所有子民服從 => 萬能上帝不是萬能 . 結論 : 萬能上帝不存在。
Conclusion: 1. S is not a set!! 2. If a language is too powerful, it may produce expressions that is
meaningless or can not be realized. Question: If HALT(P,X) can be programmed, will it incur any absurd result
like the case of S?Ans: yes!!
The Foundations
Transparency No. 2-40
H(P) : a program that HALT(-,-) cannot predict
Notes: 1. H(P) is simply { L : if(HALT(P,P)) then goto L } 2. H uses HALT(-,-) as a subroutine. 3. H(P) halts iff HALT(P,P) returns false iff P(P) does not halt. 4. Let input P be H H(H) halts iff H(H) does not halt. HALT is not a correct implementation!
H(P)
Pr(x:String) {…..
}
P
P(P) Halt ?
yestrue
no false
HALT(P,X) Loop
haltP
P
The Foundations
Transparency No. 2-41
The growth of functions ( Section 3.2, 6th edition)
If f is a positive valued function, then what do the following terms mean? O(f) means ? (f) means ? (f) means ? useful in the analysis of the efficiency of
computer algorithms.
The Foundations
Transparency No. 2-42
Problem, algorithm and Complexity
A problem is a general question: description of parameters [input] description of solution[output] description of how the outputs are related to the
inputs. An algorithm is a step by step procedure to get
the related output (i.e., answer) from the given input. a recipe a computer program
We want the most efficient algorithm fastest (mostly) most economical with memory (sometimes) expressed as a function of problem input size
The Foundations
Transparency No. 2-43
Parameters: Set of cities Inter-city distances
Example: Traveling Salesman Problem
c
bd
a
3
5
6
9
910
The Foundations
Transparency No. 2-44
Solution [output]
Solution: The shortest tour passing all cities Example: a,b,d,c,a has length 27
c
bd
a
3
5
6
9
910
The Foundations
Transparency No. 2-45
Problem Size
What is appropriate measure of problem size? m nodes? m(m+1)/2 distances?
Use an encoding of the problem alphabet of symbols: a,b,c,d,0-9, |. strings: abcd||10|5|9|6|9|3.
Measures Problem Size: length of encoding. Time Complexity: how long an algorithm takes,
as function of problem size.
The Foundations
Transparency No. 2-46
Time Complexity
What is tractable? A function f(n) is O(g(n)) whenever ∃ c > 0 n∃ 0 > 0 s.t. |f(n)| ≤ c ∙ |g(n)| for all n > n0.
A polynomial time algorithm is one whose time complexity is O(p(n)) for some polynomial p(n).
An exponential time algorithm is one whose time complexity cannot be bounded by a polynomial
(e.g., nlog n or 2n).
The Foundations
Transparency No. 2-47
Tractability Basic distinction:
polynomial time = tractable exponential time = intractable
10 20 30 40 50 60
n .00001s .00002s .00003s .00004s .00005s .00006s
n2 .0001s .0004s .0009s .0016s .0025s .0036s
n3 .001s .008s .027s .064s .125s .216s
n5 .1s 3.2s 24.3s 1.7 m 5.2 m 13.0 m
2n .001s 1.0s 17.9s 12.7d 35.7 y 366c
3n .059 s 58 m 6.5 y 3855 c 2∙108c 1.3∙10 13 c
execution time in microseconds(μs)
problem size
The Foundations
Transparency No. 2-48
Effect of Speed-ups for different order of functionsWait for faster hardware! Consider maximum problem size you can solve in an
hour. present 100 times faster 1000 times faster
n N1 100 N1 1000 N1
n2 N2 10N2 31.6 N2
n3 N3 4.64 N3 10 N3
n5 N4 2.5 N4 3.98 N4
2n N5 N5+6.64 N5+9.97
3n N6 N6+4.19 N6+2.29
The Foundations
Transparency No. 2-49
Asymptotic notations
Asymptotic analysis: care the value of f(n) only when n is very large. discard the difference of f and g when limit f/g is
bounded by two positive numbers (a,b).
((g(n)) = { f(n) | c and k > 0 s.t. f(n) cg(n) for all n > k }
((g(n)) = { f(n) | c2,c1 and k > 0 s.t. c2g(n) f(n) c1 g(n) for all n > k }
((g(n)) = { f(n) | c and k > 0 s.t. c g(n) f(n) for all n > k }
The Foundations
Transparency No. 2-50
Examples
Ex1: Show that f(x) = x2 + 2x+ 1 is O(x2).
pf: Let c = 4, k = 1, It is easy to check that if x > k, then f(x) = x2 + 2x+ 1 ≤ x2 + 2 x2 + x2 ≤ c x2.
Hence by definition, f(x) = O(x2).
Ex2: Show that f(x) = x2 + 2x+ 1 is (x2).
pf: Let c = 1, k = 1. Obviously, x2+2x+1 ≥ x2 = cx2 for all x >1=k. Hence f(x) = (x2).
The Foundations
Transparency No. 2-51
Ex2: Show that f(x) = x2 + 2x+ 1 is (x2).
pf: Let c1 = 1,c2=4, k = 1.
c1x2 ≤ x2+2x+1 ≤ c2 x2 for all x >1=k. Hence f(x) = (x2).
Proposition: f = (g) iff f = (g) and f = (g).pf: (=>:) direct from definition.(<=:) if f = O(g) = (g)
=> c∃ 1, k1 s.t f(x) ≤ c1 g(x) for all x > k1.
∃ c2, k2 s.t f(x) ≥ c2 g(x) for all x > k2.
let k = max(k1,k2) =>
c2 g(x) ≤ f(x) ≤ c1 g(x) for all x > k. Hence f(x) = (g).
The Foundations
Transparency No. 2-52
Using the asymptotic notations
We use f(n) = (g(n)) to mean f(n) (g(n)), where = .
analogy: O (asymptotic upper bound): f(n) = O(g(n)) behaves like f(n) g(n) (asymptotic lower bound): f(n) =(g(n)) behaves like f(n) g(n)
(asymptotic tight bound : =
f(n) = (g(n)) behaves like f(n) = g(n)