Presentation is loading. Please wait.

Presentation is loading. Please wait.

Discrete Structures Li Tak Sing( 李德成 ) Lecture note 2 1.

Similar presentations


Presentation on theme: "Discrete Structures Li Tak Sing( 李德成 ) Lecture note 2 1."— Presentation transcript:

1 Discrete Structures Li Tak Sing( 李德成 ) Lecture note 2 1

2 Prove that power(A  B)=power(A)  power(B) 2

3 Proof x  power(A)  power(B)  x  power(A) and x  power(B)  x  A and x  B  x  A  B  x  power(A  B) Therefore power(A  B)=power(A)  power(B) 3

4 Counting finite sets The size of a set S is called its cardinality and is denoted as |S| |  |=0 Counting a union set: |A  B|=|A|+|B|-|A  B| |A  B  C|=|A|+|B|+|C|-|A  B|-|B  C|- |C  A|+|A  B  C| |A-B|=|A|-|A  B| 4

5 Counting example In a class, 15 students study economics, 20 students study history, 13 students study literature, 5 students study both both economics and history, 7 students study both history and literature, 4 students study both literature and economics, no students study all three courses. 4 students study none of these courses. What is the number of students in the class. 5

6 Counting example(solution) |E|=15 |H|=20 |L|=13 |E  H|=5 |H  L|=7 |L  E|=4 |H  L  E|=0 6

7 Counting example(solution) Therefore |H  L  E|=|H|+|L|+|E|-|H  L|-|L  E|-|E  H|+ |H  L  E| =15+20+13-5-7-4+0 =32 Therefore the number of students in the class is 32+4=36. 7

8 More examples Suppose a highway survey crew noticed the following information about 500 vehicles: In 100 vehicles the driver was smoking, in 200 vehicles the driver was talking to a passenger, and in 300 vehicles the driver was tuning the radio. Further, in 50 vehicles the driver was smoking and talking, in 40 vehicles the driver was smoking and tuning the radio, and in 30 vehicles the driver was talking and tuning the radio, in 10 vehicles the driver was smoking, talking and tuning the radio. Find the number of vechicles in which the driver was not talking, smoking nor tuning the radio. 8

9 Solution |S|=100, |T|=200, |R|=300, |S  T|=50, |S  R|=40, |R  T|=30 |S  T  R|=10 |S  T  R|=100+200+300-50-40-30+10 =490 Therefore |(S  T  R)'|=500-490=10 9

10 Ordered structures A tuple is a number of elements with a distinct order. An n-tuple contains n elements and is denoted as (x 1, x 2,...,x n ) where x 1, x 2,..., x n are the n elements of the tuple. For example, (3,2) is a 2-tuple, while () is a 0-tuple. 2-tuples are also called ordered pairs. 10

11 Two characteristics of tuples There may be repeated occurrences of elements. There is an order or arrangement of the elements. 11

12 Cartesian Product of Sets If A, B are sets, then the Cartesian product of A and B, which is denoted as A  B, is the set of all ordered pairs (a,b) such that a  A and b  B. A  B={(a,b)| a  A and b  B} For example, if A={1,2}, B={a,b,c}, then A  B={(1,a),(1,b),(1,c),(2,a),(2,b),(2,c)} |A  B|= |A|  |B| 12

13 Cartesian products of A 1, A 2,...,A n A 1  A 2 ....  A n ={(a 1,a 2,..,a n )|x i  A i } |A 1  A 2 ....  A n |= |A 1 |  |A 2 | ....  |A n | If all the sets are identical, we can write it as A n. If A={1,a}, then A 0 ={()}, A 1 ={(1),(a)}, A 2 ={(1,1),(1,a),(a,1),(a,a)} 13

14 Examples 1.Write down all possible 3-tuples over the set {a,{a}}. 2.Let A={1,2} and B={2,3}. Compute each of the following: 1.A  B 2.A 2 3.A 2  (A  B) 14

15 Solution 1.{(a,a,a),(a,a,{a}),(a,{a},a),(a,{a},{a}), ({a},a,a),({a},,a,{a}),({a},,{a},a),({a},{a},{a})} 2. 1. {(1,2),(1,3),(2,2),(2,3)} 2. {(1,1),(1,2),(2,1),(2,2)} 3. {(1,2),(2,2)} 15

16 Arrays, matrices, records A one dimensional array of size n is an n- tuple. A two dimensional array is a matrix. A matrix of size m  n is an m-tuple of n- tuples. 16

17 This 2  3 matrix can be represented by an 2- tuple of 3-tuples: a=((1,3,-2),(3,2,3)) 17

18 Lists A list is a finite ordered sequence of zero or more elements that can be repeated. What is the difference between a list and a tuple? For a tuple, you can access any member of it directly. For a list, you have access to two entity: head which is the first element and a tail which is a list that contains the remaining elements. 18

19 Lists <> represents the empty list. represents a list with three elements.,2> represents a list with three elements. The second element is a list. 19

20 Head, tail head(L) represents the head of the list L. head( )=1 head(<>) is an error tail(L) represents the tail of L. tail( )= (note that it is a list) tail( )= tail( )=<> tail(<>) is an error 20

21 cons cons(h,L) represent the concatenation of h and L to form another list. cons(1, )= cons(, )=,23> The cons operation can also be written as :: cons(x,y)=x::y 1:: =cons(1, )= 21

22 Computer representation of lists Each element of a list is allocated a memory block so that the block contains two things, the value of the element and the address to the next element. 22

23 Memory representation of a list L= M=cons(3,L)= 23

24 Examples 1.Write down all possible lists of length 2 or less over the set A={a,b}. 2.Find the head and tail of each of the list. 1.<> 2. 3. > 4. > 5., > 24

25 Solution 1.<>,,,,,, 2.1. head(<>)=error, tail(<>)=error 2. head( )=a, tail( )=<> 3. head( >)=, tail( >)=<> 4. head ( >)=a, tail( >)= > 5. head(, >)= tail(, >)= > 25

26 Strings A string is a finite ordered sequence of zero or more elements that are placed next to each other. The individual elements that make up a string are taken from a finite set called an alphabet. Let the alphabet be A={a,b}. A string over {a,b} can be b, aa, bba, etc. 26

27 Empty string is a string with no elements and is denoted as . The length of a string s is denoted as |s|. Two string s and t can be concatenated as st. For example if s is aab and t is bba, then st is aabbba. For a string s, ss can be written as s 2, and the concatenation of n s is s n. s 0 = . 27

28 Languages A language is a set of strings. If A is an alphabet, then a language over A is a set of strings over A. The set of all strings over A is denoted by A*, so a language over A is a subset of A*. For example, if A={a,b}, the following are languages over A: {ab}, {aab, bab}, {} 28

29 Example of languages {a n |n  N} {a m b n |m,n  N} 29

30 Products of Languages The product of languages L and M is the language LM={st| s  L and t  M} L={13,44}, M={a, aa}, then LM={13a,13aa,44a,44aa} L n ={s 1 s 2...s n |s i  L} if L={a,ab}, then L 0 ={  } L 1 ={a,ab} L 2 ={aa, aab, aba, abab} 30

31 If L is a language, then L 0  L 1 ....  L n ..... is the closure of L and is denoted as L*. An element of L* is either  or a concatenation of strings from L. if L={a, ab}, then the followings are elements of L*: aaaabaabaaa, abababaaa,.... Closures 31

32 Positive closures L + = L 1 ....  L n ..... is the positive closure of L. L*={  }  L + but L + may not equal to L*-{  } because L + may itself contain , in this case L*=L +. If L={ ,a}, then, L*=L + ={ ,a,a 2,a 3,...} 32

33 Examples Let L={ ,a,bb} and M={ba,aa}. Evaluate each of the following language expresssion: 1.LM 2.ML 3.L 0 4.L 1 5.L 2 33

34 Solution 1.{ba,aa,aba,aaa,bbba,bbaa} 2.{ba,baa,babb,aa,aaa,aabb} 3.{  } 4.{ ,a,bb} 5.{ ,a,bb,aa,abb,bba,bbbb} 34

35 Use your wits to solve each of the following language equations for the unknown language. 1.{ ,a,ab}L={b,ab,ba,aba,abb,abba} 2.L{a,b}={a,baa,b,bab} 3.{a,aa,ab}L={ab,aab,abb,aa,aaa,aba} 4.L{ ,a}={ ,a,b,ab,ba,aba} 35

36 Solution 1.{b,ba} 2.{ ,ba} 3.{b,a} 4.{ ,b,ab} 36

37 Example Let L and M be two languages. For each of the following languages describe the general structure of a string x by writing it as a concatenation of strings that are in either L or M. 1.LML 2.LM* 3.(L  M)* 4.(LM)* 37

38 Solution 1.LML={abc|a,c  L and b  M} 2.LM*={ab 1 b 2.... b n | a  L and b i  M where 1  i  n and 0  n} 3.(L  M)*={b 1 b 2.... b n | b i  L  M where 1  i  n and 0  n} 4.(LM)*={a 1 b 1 a 2 b 2.... a n b n | a i  L, b i  M where 1  i  n and 0  n} 38

39 Example Try to describe each of the following languages in some way. 1.{a,b}*  {b,c}* 2.{a,b}*-{b}* 3.{a,b,c}*-{a}* 39

40 Solution 1.{b}* 2.All strings that contains only a or b and there is at least one a in the string. 3.All strings that contains only a, b or c and there is at least one b or c in the string. 40

41 Relations If R is a subset of A 1  A 2 ...  A n, then, R is said to be an n-ary relation on A 1  A 2 ...  A n. For example, assume A 1 ={tom, peter, kelvin}, A 2 ={mary, jessy}. Now, tom, peter are husbands of mary and jessy respectively. If we define R to a relation that represents marriage, then tom and mary are related this way. 41

42 So R={(tom,mary),(peter,jessy)}. Note that R  A 1  A 2. Let A={1,4}, B={3,9}. Let R represents the relation that an integer from A is less than an integer from B. So R contains the following elements: {(1,3),(1,9),(4,9)}. We can also write R as: R={(x,y)|x  A and y  B and x<y} 42

43 If R is a relation and (x 1,x 2,...,x n )  R, we would write: R(x 1,x 2,...,x n ). For a binary relation, R(x 1,x 2 ) is usually written as x 1 R x 2. 43

44 An example. Assume that A={1,2,..,10}. Find the relation R so that: R={(x,y)| x,y  A and x 2 =y} 44

45 Solution R={(1,1),(2,4),(3,9)} 45

46 Examples Represent each relation as a set by listing each individual tuple. 1.{d| d  N and d>0 and d divides 12} 2.{(d,n)| d,n  {2,3,4,5,6} and d divides n} 3.{(x,y,z)|x=y+z, where x,y,z  {1,2,3}} 46

47 Solution 1.{1,2,3,4,6,12} 2.{(2,2),(2,4),(2,6),(3,3),(3,6),(4,4),(5,5),(6,6 )} 3.{(2,1,1),(3,1,2),(3,2,1)} 47


Download ppt "Discrete Structures Li Tak Sing( 李德成 ) Lecture note 2 1."

Similar presentations


Ads by Google