350 likes | 573 Views
Discrete Structures. Li Tak Sing( 李德成 ). 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|-|AB| |A BC|=|A|+|B|+|C|-|AB|-|BC|-|CA|+|AB C| |A-B|=|A|-|AB|. Counting example.
E N D
Discrete Structures Li Tak Sing(李德成)
Counting finite sets • The size of a set S is called its cardinality and is denoted as |S| • ||=0 • Counting a union set:|AB|=|A|+|B|-|AB| • |ABC|=|A|+|B|+|C|-|AB|-|BC|-|CA|+|AB C| • |A-B|=|A|-|AB|
Counting example • In a class, 15 students study economics, 20 students study history, 10 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. What is the number of students in the class. 4 students study none of these courses. What is the number of students in the class.
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. What can you say about the number of drivers who were smoking, talking and tuning the radio.
Ordered structures • A tuple is a number of elements with a distinct order. An n-tuple contains n elements and is denoted as (x1, x2,...,xn) where x1, x2, ..., xn 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.
Two characteristics of tuples • There may be repeated occurrences of elements. • There is an order or arrangement of the elements.
Cartesian Product of Sets • If A, B are sets, then the Cartesian product of A and B, which is denoted as AB, is the set of all ordered pairs (a,b) such that aA and bB. • AB={(a,b)| aA and bB} • For example, if A={1,2}, B={a,b,c}, then AB={(1,a),(1,b),(1,c),(2,a),(2,b),(2,c)} • |AB|= |A||B|
Cartesian products of A1, A2, ...,An • A1A2 .... An={(a1,a2,..,an)|xiAi} • |A1A2 .... An|= |A1||A2|....|An| • If all the sets are identical, we can write it as An. • If A={1,a}, thenA0={()}, A1={(1),(a)}, A2={(1,1),(1,a),(a,1),(a,a)}
Examples • Write down all possible 3-tuples over the set {a,{a}}. • Let A={1,2} and B={2,3}. Compute each of the following: • AB • A2 • A2 (AB)
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 mn is an m-tuple of n-tuples.
This 23 matrix can be represented by an 2-tuple of 3-tuples:a=((1,3,-2),(3,2,3))
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.
Lists • <> represents the empty list. • <1,2,2> represents a list with three elements. • <1,<1,2,3>,2> represents a list with three elements. The second element is a list.
Head, tail • head(L) represents the head of the list L. head(<1,2,3>)=1head(<>) is an error • tail(L) represents the tail of L.tail(<1,2,3>)=<2,3> (note that it is a list)tail(<1,2>)=<2>tail(<1>)=<>tail(<>) is an error
cons • cons(h,L) represent the concatenation of h and L to form another list. • cons(1,<2,3>)=<1,2,3> • cons(<1>,<2,3>)=<<1>,23>
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.
Memory representation of a list L=<1,2,2> M=cons(3,L)=<3,1,2,2>
Examples • Write down all possible lists of length or less over the set A={a,b}. • Find the head and tail of each of the list. • <> • <a> • <<a>> • <a,<b,c>> • <<a,b>,<c,d>>
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.
Empty string is a string with no elements and is denoted as . • The length of a string s is denoted as |s|. • Strings are lists are both finite sequences of elements. • For a string s, ss can be written as s2, and the concatenation of n s is sn. • s0=.
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}, {}
Example of languages • {an|nN} • {ambn|m,nN}
Products of Languages • The product of languages L and M is the language LM={st| sL and tM} • L={13,44}, M={a, aa}, then LM={13a,13aa,44a,44aa} • Ln={s1s2...sn|siL}if L={a,ab}, then L0={} • L1={a,ab} • L2={aa, aab, aba, abab}
Closures • If L is a language, then L0L1....Ln..... 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, ....
Positive closures • L+= L1....Ln..... 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,a2,a3,...}
Examples • Let L={,a,bb} and M={ba,aa}. Evaluate each of the following language expresssion: • LM • ML • L0 • L1 • L2
Use your wits to solve each of the following language equations for the unknown language. • {,a,ab}L={b,ab,ba,aba,add,abba} • L{a,b}={a,baa,b,bab} • {a,aa,ab}L={ab,aab,abb,aa,aaa,aba} • L{,a}={,a,b,ab,ba,aba}
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. • LML • LM* • (LM)* • (LM)*
Try to describe each of the following languages in some way. • {a,b}*{b,c}* • {a,b}*-{b}* • {a,b,c}*-{a}*
Relations • If R is a subset of A1A2...An, then, R is said to be an n-ary relation on A1A2...An. • For example, assume A1={tom, peter, kelvin}, A2={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.
So R={(tom,mary),(peter,jessy)}. Note that R A1A2. • 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)|xA and yB and x<y}
If R is a relation and (x1,x2,...,xn)R, we would write: R(x1,x2,...,xn). • For a binary relation, R(x1,x2) is usually written as x1Rx2.
An example. Assume that A={1,2,..,10}. Find the relation R so that:R={(x,y)| x,yA and x2=y}
Examples • Represent each relation as a set by listing each individual tuple. • {(d,12)| d>0 and d divides 12} • {(d,n)| d,n {2,3,4,5,6} and d divides n} • {(x,y,z)|x=y+z, where x,y,z {1,2,3}}