Discrete Mathematics: Harper Langston New York University
Discrete Mathematics: Harper Langston New York University
Lecture 8
Harper Langston
New York University
Generic Functions
• A function f: X Y is a relationship between
elements of X to elements of Y, when each
element from X is related to a unique element
from Y
• X is called domain of f, range of f is a subset of Y
so that for each element y of this subset there
exists an element x from X such that y = f(x)
• Sample functions:
– f : R R, f(x) = x2
– f : Z Z, f(x) = x + 1
– f : Q Z, f(x) = 2
Generic Functions
• Arrow diagrams for functions
• Non-functions
• Equality of functions:
– f(x) = |x| and g(x) = sqrt(x2)
• Identity function
• Logarithmic function
One-to-One Functions
• Function f : X Y is called one-to-one
(injective) when for all elements x1 and x2
from X if f(x1) = f(x2), then x1 = x2
• Determine whether the following functions
are one-to-one:
– f : R R, f(x) = 4x – 1
– g : Z Z, g(n) = n2
• Hash functions
Onto Functions
• Function f : X Y is called onto (surjective)
when given any element y from Y, there exists x in
X so that f(x) = y
• Determine whether the following functions are
onto:
– f : R R, f(x) = 4x – 1
– f : Z Z, g(n) = 4n – 1
• Bijection is one-to-one and onto
• Reversing strings function is bijective
Inverse Functions
• If f : X Y is a bijective function, then it is
possible to define an inverse function f-1: Y
X so that f-1(y) = x whenever f(x) = y
• Find an inverse for the following functions:
– String-reverse function
– f : R R, f(x) = 4x – 1
• Inverse function of a bijective function is a
bijective function itself
Pigeonhole Principle
• If n pigeons fly into m pigeonholes and n > m, then at
least one hole must contain two or more pigeons
• A function from one finite set to a smaller finite set
cannot be one-to-one
• In a group of 13 people must there be at least two who
have birthday in the same month?
• A drawer contains 10 black and 10 white socks. How
many socks need to be picked to ensure that a pair is
found?
• Let A = {1, 2, 3, 4, 5, 6, 7, 8}. If 5 integers are selected
must at least one pair have sum of 9?
Pigeonhole Principle
• Generalized Pigeonhole Principle: For any function f : X Y
acting on finite sets, if n(X) > k * N(Y), then there exists some
y from Y so that there are at least k + 1 distinct x’s so that f(x)
=y
• “If n pigeons fly into m pigeonholes, and, for some positive k,
m >k*m, then at least one pigeonhole contains k+1 or more
pigeons”
• In a group of 85 people at least 4 must have the same last
initial.
• There are 42 students who are to share 12 computers. Each
student uses exactly 1 computer and no computer is used by
more than 6 students. Show that at least 5 computers are used
by 3 or more students.
Composition of Functions
• Let f : X Y and g : Y Z, let range of f be a
subset of the domain of g. The we can define a
composition of g o f : X Z
• Let f,g : Z Z, f(n) = n + 1, g(n) = n^2. Find f o
g and g o f. Are they equal?
• Composition with identity function
• Composition with an inverse function
• Composition of two one-to-one functions is one-
to-one
• Composition of two onto functions is onto
Cardinality
• Cardinality refers to the size of the set
• Finite and infinite sets
• Two sets have the same cardinality when there is bijective
function associating them
• Cardinality is is reflexive, symmetric and transitive
• Countable sets: set of all integers, set of even numbers,
positive rationals (Cantor diagonalization)
• Set of real numbers between 0 and 1 has same cardinality
as set of all reals
• Computability of functions
Recursive Sequences
• A recurrence relation for a sequence a0, a1, a2, …
is a formula that relates each term ak to certain
collection of its predecessors. Each recurrence
sequence needs initial conditions that make it
well-defined
• Famous recurrences: algebraic and geometric
sequences, factorial, Fibonacci numbers
• Tower of Hanoi problem
• Compound interest
Solving Recurrences
• Iteration method
• Telescoping (Bubble-Sort)
• Range transformation (T.O.H.)
• Domain transformation (Binary Search)
• Both (Mergesort)
See http://www.cs.nyu.edu/courses/summer04/G22.1170-001/2-Math.ppt
• Guess and plug-in
• Master Theorem
• Recurrences involving sum
Second-Order Homogenous
Recurrences
• Second-order homogeneous relation with
constant coefficients is a relation of the
form: ak = A * ak-1 + B * ak-2, where A and B
are constants
• Characteristics equation
• Distinct roots case: Fibonacci numbers
• Single root case: gambler’s ruin
Classes of Functions
• Constants
• Polynoms: linear, quadratic
• Exponents
• Logarithms
• Functions in between
• Relationship between different classes
O-notation
• Function f(n) is of order g(n), written f = O(g),
when there exists number M such that there exists
number n0 so that for all n > n0 we have f(n) <= M
* g(n)
• If f is O(g), then g is (f), or in other words, when
for all numbers M and for all numbers no, there
exists n > n0 such that f(n) > M * g(n)
• If f is O(g) and g is O(f), then we say that f is (g)
or that f and g are of the same order