180 likes | 301 Views
Discrete Structures. Li Tak Sing( 李德成 ) mt263f-10.ppt. Hash examples.
E N D
Discrete Structures Li Tak Sing(李德成) mt263f-10.ppt
Hash examples • Let S={one,two,three, four, five, six, seven, eight, nine} and let f:SN9 be defined by f(x)=(3|x|) mod 9, where |x| means the number of letters in x. For each of the following gaps, construct a hash table that contains the strings of S by choosing a string for entry in the table by the order that it is listed in S. Resolve collisions by linear probing with the given gap and observe whether all strings can be placed in the table. • Gap=1 • Gap=2 • Gap=3
Countability • Let A and B be sets. If there is a bijection between A and B, we'll denote the fact by writing |A|=|B|. • In this case, we'll say that A and B have the same size or have the same cardinality.
Finite sets examples • Find the cardinality of each set by establishing a bijection between it and a set of the form {0,1,...,n}. • {2x+5|xN and 12x+5100}. • {x2|x N and 0x2 500} • {2,5,8,11,...,44,47}
Cardinality of an infinite set • Let Odd denote the set of odd natural numbers. Then the function f:NOdd defined by f(x)=2x+1 is a bijection. Therefore |N|=|Odd|. • If there is an injection from A to B, we then |A||B|. • If there is an surjection from B to A, we have |A||B|. • If there is an injection from A to B, but no bijection between them, then|A|<|B|.
Sets that are countable • A set is countable if it is finite or if there is a bijection between it and N. In the latter case, the set is said to be countably infinite. • S is countable if |S|=n where n is a natural number or |S|=|N|
Countable Properties • Every subset of N is countable. • S is countable iff |S|<|N|. • Any subset of a countable set is countable. • Any image of a countable set is countable.
Proof of rule 1 • If the subset is finite, then it is countable. If it is not finite, we can arrange the elements in ascending order and denote the elements as xo, x1, ...... So there is a bijection between {xo, x1,...} and N.
Proof of rule 2 • If SN is countable, then either |S|=n or |S|=|N|. So |S||N|. • If |S||N|, then, there is an injection f from S to N. Now, |S|=|f(S)|. Now, f(S) is a subset of N, by rule 1, f(S) is countable. Therefore f(S) is either finite or |f(S)|=|N|. This imply either S is finite or |S|=|N|. Both imply that S is countable.
Proof of rule 3 • If A is a countable set, then there is an injection from A to N. Assume that f:AN be one of the injective functions. Now, for any subject B of A, we define the function g: B N such that g(x)=f(x). It is obvious that g is also an injection. Therefore B is also countable.
Proof of rule 4 • If A is a countable set, then there is an injection from A to N. Let f:A N be an injection. Now, for a function g: A B for every yg(A), there is an x A such that g(x)=y. Now, we define a function h: g(A) A such that h(y)=x so that g(x)=y and f(x) is maximum. Now, h must be an injection because an element in A cannot map with two different elements in B under g. Therefore, fh is an injection as both f and h are injections. fh is a function from g(A) to N. So g(A) is countable.
NxN is countable • (0,0) has 1 element • (0,1), (1,0) have 2 elements • (0,2),(1,1),(2,0) have 3 elements • ..... • (0,n), (1,n-1),.....(0,n) have n+1 elements
(0,0) maps to 0, • (0,1), (1,0) map to 1,1+1 • (0,2),(1,1),(2,0) map to (1+2),(1+2)+1,(1+2)+2 • ..... • (0,n), (1,n-1),.....(0,n) maps to (1+2+..n), (1+2+..n)+1,.....(1+2+...n)+n
(0,0) maps to 0, • (0,1), (1,0) map to 1,2 • (0,2),(1,1),(2,0) map to 3,4,5 • ..... • (0,n), (1,n-1),.....(0,n) maps to (n2+n)/2, (n2+n)/2,....., (n2+n)/2+n
Counting unions of countable sets • If So, S1,....Sn,.... is a sequence of countable sets, then the union SoS1 .... Sn .... is a countable set.
Proof • List the elements of Sn as xn0, xn1,..... • If Sn is finite, then repeat one of the elements indefinitely so that we have an infinite sequence of elements. • If So, S1,....Sn,.... is a finite sequence, then we repeat one of the set indefinitely so that we have an infinite sequence of sets. • (m,n) of NN is associated with xmn • The mapping is not bijective because some elements of NN is mapped to the same xmn. • However, the mapping is surjective because every element of xmn is associated with (m,n). So we have |N|=|NN|| SoS1 .... Sn .... | and therefore SoS1 .... Sn .... is countable.
Countability of the rationals • Q+ ={m/n | m,nN and m,n0 } • We can associate each m/n with (m,n)NN. Therefore, |Q+||NN|=|N|. Therefore Q+ is countable. • Similary Q- ={-m/n | m,nN and m,n0 } and is also countable. • Therefore Q= Q+{0} Q- should be countable.
Examples • Show that each of the following sets is countable by establishing a bijection between the set and N. • The set of even natural numbers. • The set of negative integers. • The set of strings over {a} • The set of strings over {a} that have even length. • The set Z of integers. • The set of odd integers. • The set of even integers.