220 likes | 414 Views
Discrete Structures. Li Tak Sing( 李德成 ). Minimum depth of a binary tree.
E N D
Discrete Structures Li Tak Sing(李德成)
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 2nx<2n+1, then we have nlog2x<n+1 and therefore the minimum depth is log2x
Problems in functions • Let f: AB be a function, and let E and F be subsets of A. Prove each of the following facts about images. • f(EF)=f(E)f(F) • f(EF)=f(E)f(F)
Constructing Functions • Composition of Functions. The composition of two functions f and g is the function denoted by fg and is defined by (fg)(x)=f(g(x)) • This definition would only make sense if f:AB and g:CD and BC.
Examples • f:RR and f(x)=3x+2 • g:RR and g(x)=x2+x • Find fg and gf
The Sequence, Distribute, and Pairs Functions • seq: N lists(N)seq(n)=<0,1,...,n>For example seq(3)=<0,1,2,3> • dist:Alists(B)lists(AB)dist(x,<r,s,t>)=<(x,r),(x,s),(x,t)> • pairs:lists(A)lists(B)lists(AB)pairs(<a,b,c>,<d,e,f>)+<(a,d),(b,e),(c,f)>
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))
A list of pairs • f(n)=<(0,0),(1,1),..(n,n)> =pairs(seq(n),seq(n))
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: (AB)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>
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
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, -, *}.
Properties of Functions • Injections • A function f: AB is called injective (or called one-to-one) if it maps distinct elements of A to distinct elements of B. • If f: AB is called injective, then x,yA, f(x)=f(y) x=y
Injective or not? • f:RR, f(x)=sin(x) • f:R R, f(x)=x2 • f:R+ R, f(x)=logex
Surjective Functions • A function f:AB 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.
Surjective or not? • f:R R, f(x)=x2 • f:R R, f(x)=sin(x) • f:R+ R, f(x)=logex
Bijections • A function is called bijective if it is both injective and surjective.
Bijective or not • f:R R, f(x)=x2 • f:R R, f(x)=sin(x) • f:R+ R, f(x)=logex
Inverse functions • Bijections always come in pairs. If f: AB is a bijection, then there is a function g: BA, 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.
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.
Problems • In each case, find an example of a function f:NN satisfying the given condition. • Injective but not surjective. • Surjective but not injective. • Bijective but not the identity function.
Problem • Left f:R+R+ be defined by f(x)=x/(x+5). • Show that f is injective. • Show that if is not surjective.
Injective and surjective relationships • If f and g are injective, then fg is injective. • If f and g are surjective, then fg is surjective. • If f and g are bijective, then fg is bijective. • There is an injection from A to B iff there is a surjection from B to A.