1 / 22

Discrete Structures

Discrete Structures. Li Tak Sing( 李德成 ). Minimum depth of a binary tree.

nishi
Download Presentation

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. Minimum depth of a binary tree • A full binary tree of depth n should have 2n nodes. So if we have 2n nodes, the minimum depth of the tree is n. We note that:log22n=n, so if the number of node is x so that 2nx<2n+1, then we have nlog2x<n+1 and therefore the minimum depth is log2x

  3. Problems in functions • Let f: AB be a function, and let E and F be subsets of A. Prove each of the following facts about images. • f(EF)=f(E)f(F) • f(EF)=f(E)f(F)

  4. Constructing Functions • Composition of Functions. The composition of two functions f and g is the function denoted by fg and is defined by (fg)(x)=f(g(x)) • This definition would only make sense if f:AB and g:CD and BC.

  5. Examples • f:RR and f(x)=3x+2 • g:RR and g(x)=x2+x • Find fg and gf

  6. The Sequence, Distribute, and Pairs Functions • seq: N  lists(N)seq(n)=<0,1,...,n>For example seq(3)=<0,1,2,3> • dist:Alists(B)lists(AB)dist(x,<r,s,t>)=<(x,r),(x,s),(x,t)> • pairs:lists(A)lists(B)lists(AB)pairs(<a,b,c>,<d,e,f>)+<(a,d),(b,e),(c,f)>

  7. Composing functions with different arities • Composition can also occur between functions with different arities. • f(X)=h(g1(X), g2(X), ...,gn(X)). • Example: f(x,y)=dist(x,seq(y))

  8. A list of pairs • f(n)=<(0,0),(1,1),..(n,n)> =pairs(seq(n),seq(n))

  9. The Map Function • Let f be a function with domain A and let <x1,...,xn> be a list of elements from A. Then map(f, <x1,...,xn> )=<f(x1),....,f(xn)> • map: (AB)lists(A) lists(B) • Example, map(f,<1,2,3>)=<f(1),f(2),f(3)> • map(+, <(1,2),(4,3)>)=<+(1,2),+(4,3)>=<3,7>

  10. Examples • For each function, find the image of the set {1,2,3,4,5,6,7,8,9,10} • f(x)=ceiling(log2(x)). • f(x)=floor(log2(x)). • Describe the set of natural numbers x such that floor(log2(x)=15 • Describe the set of natural numbers x such that ceiling(log2(x))=15

  11. Examples • Let f be defined informally by f(n)=<2n, 2n-2, 2n-4,..0>. Express f as a composition of known function from the set {seq, dist, pairs, map, -, *}.

  12. Properties of Functions • Injections • A function f: AB is called injective (or called one-to-one) if it maps distinct elements of A to distinct elements of B. • If f: AB is called injective, then x,yA, f(x)=f(y) x=y

  13. Injective or not? • f:RR, f(x)=sin(x) • f:R R, f(x)=x2 • f:R+ R, f(x)=logex

  14. Surjective Functions • A function f:AB is called surjective (also onto) if the range of f is the codomain B. • f:A B is surjective iff for each element in B, there is an x in A such that f(x)=y.

  15. Surjective or not? • f:R R, f(x)=x2 • f:R R, f(x)=sin(x) • f:R+ R, f(x)=logex

  16. Bijections • A function is called bijective if it is both injective and surjective.

  17. Bijective or not • f:R R, f(x)=x2 • f:R R, f(x)=sin(x) • f:R+ R, f(x)=logex

  18. Inverse functions • Bijections always come in pairs. If f: AB is a bijection, then there is a function g: BA, called the inverse of f, defined by g(b)=a if f(a)=b. • The inverse of f is also a bijection. • There is only one inverse of f.

  19. Problems • For each property below, define a function that satisfies the property. Choose the domain and codomain for each function from the three sets. A={a,b,c,d}, B={1,2,3,4}, C={x,y} • Injective but not surjective. • Surjective but not injective. • Bijective but not the identity function. • neither injective nor surjective.

  20. Problems • In each case, find an example of a function f:NN satisfying the given condition. • Injective but not surjective. • Surjective but not injective. • Bijective but not the identity function.

  21. Problem • Left f:R+R+ be defined by f(x)=x/(x+5). • Show that f is injective. • Show that if is not surjective.

  22. Injective and surjective relationships • If f and g are injective, then fg is injective. • If f and g are surjective, then fg is surjective. • If f and g are bijective, then fg is bijective. • There is an injection from A to B iff there is a surjection from B to A.

More Related