1 / 35

Discrete Structures

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|-|AB| |A BC|=|A|+|B|+|C|-|AB|-|BC|-|CA|+|AB C| |A-B|=|A|-|AB|. Counting example.

Télécharger la présentation

Discrete Structures

An Image/Link below is provided (as is) to download presentation 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. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

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

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

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

  5. Prove that power(AB)=power(A)power(B)

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

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

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

  9. Cartesian products of A1, A2, ...,An • A1A2 .... An={(a1,a2,..,an)|xiAi} • |A1A2 .... 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)}

  10. 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: • AB • A2 • A2 (AB)

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

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

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

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

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

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

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

  18. Memory representation of a list L=<1,2,2> M=cons(3,L)=<3,1,2,2>

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

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

  21. 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=.

  22. 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}, {}

  23. Example of languages • {an|nN} • {ambn|m,nN}

  24. 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} • Ln={s1s2...sn|siL}if L={a,ab}, then L0={} • L1={a,ab} • L2={aa, aab, aba, abab}

  25. Closures • If L is a language, then L0L1....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, ....

  26. 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,...}

  27. Examples • Let L={,a,bb} and M={ba,aa}. Evaluate each of the following language expresssion: • LM • ML • L0 • L1 • L2

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

  29. 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* • (LM)* • (LM)*

  30. Try to describe each of the following languages in some way. • {a,b}*{b,c}* • {a,b}*-{b}* • {a,b,c}*-{a}*

  31. Relations • If R is a subset of A1A2...An, then, R is said to be an n-ary relation on A1A2...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.

  32. So R={(tom,mary),(peter,jessy)}. Note that R A1A2. • 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}

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

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

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

More Related