- 121 Views
- Uploaded on
- Presentation posted in: General

Chapter 2 Basic Structures: Sets, Functions, Sequences and Sums (and part of Chapter 3)

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Chapter 2 Basic Structures: Sets, Functions, Sequences and Sums(and part of Chapter 3)

By courtesy of Prof. Cheng-Chia Chen

- 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 and 5 is a set.

- How to describe a set?
1. List all its member(s).

- 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 statement or a proposition) 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)}

- 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,...}
- Q =def the set of rational numbers
- 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}.

Definition 2.

- Two sets S1, S2 are equal iff they have the same elements.
- S1 = S2 iff "x (x Î S1 <-> x Î S2).

- Venn Diagrams:
- rectangle: universal set U
- circles: sets
- points: particular elements
- point x inside circle S => x Î S
- point x outside S => x Ï S.

U

x

S

y

S2

z

w

- 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 for-all x (x Î A ⇒ x Î B).
Def 3’’ [proper subset]: A Ì B =def A Í B /\ A ¹ B.

- Exercise: Show that
- 1. For all set A (Æ Í A):
Pf: Let x be any element => x Ï Æ (by def) => x ÎÆ ⇒ x Î A holds. Hence x (x Î Æ ⇒ x Î A) and Æ Í A.

- 2. (A Í B /\ B Í A) (A = B)
- 3. A Í Æ ⇒A = Æ (because Æ Í A)

- 1. For all set A (Æ Í A):
- Diagram representation of set inclusion relationship

Def. 4: |A| = the size (cardinality) of A = # of distinct elements of A.

- Ex:
- |{1,3,3,5}| =? |{}| =?
- |the set of binary digits| =?
- |N| =? ; |Z| =? ; |{2i | i ∈ N}| =?
- |R| =?
Def. 5.

- A set A is finite iff |A| is a natural number; otherwise it is infinite.
- Two sets are of the same size (cardinality) iff there
is a 1-1 & onto mapping between them.

Def.

- A set A is said to be denumerable (or countably infinite) iff |A| = |N|.
- A set is countable iff either |A| = n for some n in N or |A| = |N|.

- 1. |N| = |Z| = |Q| = |{x | x N and x >3 }|
- 2. |R| = |(-1,1)| = |(0,1)| (define a 1-1 & onto mapping )
- 3. |(0,1)| is uncountable (by diagonalization)
By exercises 1, 2 and 3

- R is not countable.
- Q and Z are countable.

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.

- P({0,1,2}) =?
- P({}) =?
- |P({1,2,...,n})| =?

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.
- (a1,a2,...,am) = (b1,b2,...,bn) means
- (1) m = n and
- (2) ai = bi for all 1 ≤ i ≤ m.

Def. 8: [Cartesian product]

A x B =def {(a,b) | a ∈ A and b ∈ B}

A1 x A2 x ... x An =def {(a1,...,an) | ai ∈ Ai for all 1 ≤ i ≤ n}.

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 A x B is called a relation from A to B. (skip)

Problems: 1. When will A x B = B x A? (A = B or one of them is {}.)

2. |A x B| =?

- R: a binary relation on A (i.e. a subset of AxA) .
D (the diagonal set for R ) =def { x | x Î A and (x,x) Ï R}.

For each x Î A, let Ra (the raw of a) = { b Î A | (a,b) Î R}.

Then D ≠ Ra for all a Î A.

Example: Let A = {a,b,c,d,e,f} and R =

Ra ={b,d}

Rb={b,c}

Rc={c}

Rd={b,c,e,f}

Re={e,f}

Rf={a,c,d,e}

D = {a,d,f}. D¹Rx since for each xÎA, xÎD iff (x,x)ÏR iff xÏRx.

A, B : two sets with a mapping f: A B.

R :a relation from B to A (i.e., a subset of BxA).

For all x ∈ A, let

- Rf(x) ≡ {y | y ∈ A ∧ (f(x),y) ∈ R} ⊆ A, and
- D ≡ {x | x ∈ A ∧ (f(x),x) ∉ R} ⊆ A.
Then

- D ≠ Rf(x) for all x ∈ A.
Pf: Analogous to the previous one.

Notes:

1. C = {Rf(x) | x ∈ A} ⊆ 2A is a set of

subsets of A.

2. C ≠ 2A (∵ D ∈ 2A but D ∉ C).

f:A B ; R: BxA

Rfa ={b,d}

Rfb={b,c}

Rfc={c}

Rfd={b,c,e,f}

Rfe={e,f}

Rff={a,c,d,e}

D = {a,d,f}.

D¹Rfx since for each f(x)ÎB, xÎD iff (f(x),x)ÏR iff xÏRf(x).

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 R = { (y, x) | yB and x A and x y }

Define the so-called diagonal setD in terms of f as follows:

D = {x ∈ A | x Ï Rf(x) = f(x) }.

Now

(*) D is a subset of A and

(**) D f(x) for any x ∈ A:

since x ∈ D iff x Ï f(x) for each x ∈ A.

==> D is not a subset of A (∵ f is onto to 2A),

a contradiction to (*).

Hence f must not exist!!

- Theorem: The set 2N is uncountable.
- pf: 1. direct from |A| ¹ |2A| with A = N.
- 2. another proof: suppose 2N is denumerable. Then
- there is a bijection f: N -> 2N.
- let 2N = {S0,S1,S2,...} where Si = f(i).
- Now the diagonal set
- = { k | k Ï Sk }.
By diagonalization

principle, D¹ Sk for any k,

but since D is a subset of N,

by assumption,

- D must equal to Sk for
- some k. a contradiction!

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… p-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).

- 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)

- 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).

Program that you are asked to design

P

HALT(P,X)

P(x:String) {

…..

}

P(X) Halt?

true

yes

false

no

“It’s a test …”

X

- 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.

- Consider the program
int 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 x 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)

- 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!!

H(P)

HALT(P,X)

loop

P

P(P) Halt?

true

yes

P(x:String) {

…..

}

P

halt

false

no

P

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!

- union, intersection, difference, complement
- Definitions
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

- Venn diagram representations
- Ex: U = {1,...,10}, A = {1,2,3,5,8}
B = {2,4,6,8,10}

=> A È B , A Ç B , A - B , ~A =?

1. Show that ~(A È B) = ~A Ç ~B by show that

- 1. ~(A È B) Í ~A Ç ~B
- 2. ~A Ç ~B Í ~(A È B)
Pf:

1. (By definition and logic reasoning)Let x be any element in ~(A È B) . Then

x ~(A È B) iff ~(x A È B) iff x A and x B iff x ~A and x ~B.

2. Show (1) by using set builder and logical equivalence.

~(A È B) = {x | x A È B} = {x | x ~A and x ~B}

= {x | x ~A} Ç {x | x ~A} = ~A Ç ~B.

3. Show distributive law: AU(B⋂C) = (AUB)⋂(AUC) by using a 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 AU(B⋂C) iff x(AUB)⋂(AUC). Hence the equality holds.

4. Show ~(A È (B Ç C)) = (~C È ~B) Ç ~A by set identities.

Pf:

~(A È (B Ç C))

= ~A Ç ~(B Ç C)

= ~(B Ç C) Ç ~A

= (~B È ~C) Ç ~A

= (~C È ~B) Ç ~A

Def. 6

- A1,A2,...,An: n sets
- B = {A1,A2,...,An}
1. A1È A2È An = ÈB = È{i=1,..n} Ai =def ?

2. A1Ç A2Ç An = ÇB = Ç{i=1,..n} Ai =def ?

quiz: if B = {} => ÈB =?; ÇB=?

Example:

A1 = {0,2,4,6,8}, A2 = {0,1,2,3,4}, A3 ={0,3,6,9} =>

- Unordered list or array
- union, intersection, ~: time consuming.

- Bit 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 = 1 if a1 ∈ A and 0 otherwise.

- fast set operations (e.g. union and intersection)
- suitable only if U is not large
- constant size representation

- Def. 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 each x ∈ A there is exactly one

y ∈ B with (x,y) ∈ f.

3. If (x,y) ∈ f, we write f(x) = y.

4. f: A B means f is a function from A to B.

- Def. 2
If f: A B then

1. A: the domain of f; 2. B: the codomain of f

If f(a)=b then

3. b is the image of a 4. a is the preimage of b

5. range(f) = ? 6. preimage(f) = ?

- Def 4. f A x B ; S: a subset of A,
T: a subset of B

1. f(S) =def ? {y B | x S with (x,y) f}

2. f-1(T) =def ? {x A | y T with (x,y) f}

- Def. [1-1, onto, injection, surjection, bijection]
f: A -> B.

- f is 1-1 (an injection) iff?
- f is onto (surjective, a surjection) iff?
- f is 1-1 & onto <=> f is bijective (a bijection, 1-1 correspondence)

- If there is an onto mapping from A to B, then there is a 1-1 mapping from B to A.
- If there is a 1-1 mapping from A to B then there is an onto mapping from B to A.
- The onto (≥) and the 1-1 (≤) relations between sets are all preorders (i.e., reflexive and transitive) and are converse to each other. (skip)
- 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: BA defined by h(b) = any x ∈ g(b) is 1-1.

(2,3) Similar to (1).

(4) is hard butunderstandable (reference).

FIGURE 1 Assignment of Grades in a Discrete Mathematics Class.

FIGURE 2 The Function f Maps A to B.

P. 134

FIGURE 3 A One-to-One Function.

P. 137

FIGURE 4 An Onto Function.

P. 138

FIGURE 5 Examples of Different Types of Correspondences.

P. 139

- F: A B is a real valued function iff A and B are subsets of R.
- f1, f2: real valued functions
=> 1. f1+f2 (x) =?

2. f1• f2 (x) = f1(x) x f2(x).

3. f is increasing iff?

4. f is strictly increasing iff?

- 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

FIGURE 6 The Function f －1 Is the Inverse of Function f.

P. 139

FIGURE 7 The Composition of the Functions f and g.

P. 141

- f: A B; g: B C; h: C D, then
1. idA f = f = f idB

2. f(gh) = (fg) h -- associative

3. (fg)-1 = g-1 f-1

If f: A A is a bijection then

4. f f-1 = f-1f = idA.

- Sequences:
finite A-sequence -- a: [n] (or [1,n]) A

w A-sequence -- a: N (or N+) A (infinite)

B indexed A-sequence -- f: B A

- Summation rules
- S ai =def a1 + a2 + ... + an+ (...)

- a + (a+d) + (a+2d) +... =?
sol: 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 + (n-1)d) = (2a + (n-1)d) x n.

=> S = [a + (n-1)d] n/2 = (a1 + an) n/2.

- a + ar + arr + ... =
sol: 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). (This is valid only if r is not equal to 1.)

FIGURE 10 Graphs of the (a) Floor and (b) Ceiling Functions.

P. 143

+

+

+

+

+

P. 144

P. 153

P. 157

- If f is a positive valued function, then what do the following terms mean?
- O(f) means?
- W(f) means?
- Q(f) means?
- These are useful in analyses of the efficiency of computer algorithms.

- A problem is a general question:
- description of parameters [input]
- description of solutions [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

a

10

5

9

3

c

6

9

b

d

- Parameters:
- Set of cities
- Inter-city distances

a

10

5

9

3

c

6

9

b

d

- Solution:
- The shortest tour passing all cities
- Example: a, b, d, c, a has length 27

- What is an 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 a function of problem size.

- Worst-case v.s. average-case analyses – using linear search as an example

- What is tractable?
- A function f(n) is O(g(n)) whenever
- ∃ c > 0 ∃ k > 0 s.t. |f(n)| ≤ c ∙ |g(n)| for all n > k.

- 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.

- Basic distinction:
- polynomial time = tractable (e.g. average of a set of numbers)
- exponential time = intractable (e.g. satisfiability problem)

problem size

execution time in microseconds (μs)

- Wait for faster hardware!
- Consider maximum problem size you can solve in an hour.

- 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).

- O(g(n))= {f(n) | c and k > 0 s.t. f(n) cg(n) for all n > k}
- Q(g(n))= {f(n) | c2, c1 and k > 0 s.t. c2g(n) f(n) c1g(n) for all n > k}
- W(g(n)) = {f(n) | c and k > 0 s.t. cg(n) f(n) for all n > k}

Ex1: Show that f(x) = x2 + 2x+ 1 is O(x2).

Pf: Let c = 4, k = 1, and 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). (Can be generalized.)

Ex2: Show that f(x) = x2 + 2x+ 1 is W(x2).

Pf: Let c = 1, k = 1. Obviously, x2 + 2x + 1 ≥ x2 = cx2 for all x >1 = k. Hence f(x) = W(x2).

Ex2: Show that f(x) = x2 + 2x+ 1 is Q(x2).

Pf: Let c1 = 1, c2 = 4 and k = 1.

c1x2 ≤ x2 + 2x + 1 ≤ c2x2 for all x > 1 = k. Hence f(x) = Q(x2). (Can be generalized.)

Proposition: f = Q(g) iff f = O(g) and f = W(g).

Pf: (=>:) direct from definition.

(<=:) If f = O(g) = Q(g)

=> ∃ c1, k1 s.t. f(x) ≤ c1g(x) for all x > k1.

∃ c2, k2 s.t. f(x) ≥ c2g(x) for all x > k2.

Let k = max(k1,k2). => c2g(x) ≤ f(x) ≤ c1g(x) for all x > k.

Hence f(x) = Q(g).

If f1 = O(g1) and f2 = O(g2), how about the big O of (1) f1 +f2 [Thm. 2, c = c1 + c2, k = max(k1,k2)] and (2) f1 f2 [Thm. 3, c = c1 times c2, k = max(k1,k2)]?

- We use f(n) = D(g(n)) to mean f(n) D(g(n)), where D = Q, O, W.
- Analogy:
- O (asymptotic upper bound):
f(n) = O(g(n)) behaves like f(n) g(n)

- W (asymptotic lower bound):
f(n) = W(g(n)) behaves like f(n) g(n)

- Q (asymptotic tight bound: =
f(n) = Q(g(n)) behaves like f(n) = g(n)

- O (asymptotic upper bound):

- Let f and g be positive real function. Show that
- f = O(g) iff g = W(f)
2. f = Q(g) iff limit n g/f is bounded above 0

- Finding the maximal/minimal value in a finite set of integers
- Searching problem
- Linear search
- Binary search

- Sorting problem
- Bubble sort
- Insertion sort

- Shortest path problem
- Minimal cost spanning tree problem
- Low pass filtering problem for images
- Greedy algorithm for 0-1 knapsack problem
- Greedy algorithm for the traveling salesman problem
- Greedy algorithm for the multi-coloring problem
- Greedy algorithm for the minimal coin problem