CMPT 285 Discrete Mathematics - PowerPoint PPT Presentation

1 / 105
About This Presentation
Title:

CMPT 285 Discrete Mathematics

Description:

Composed of distinct, seperable parts. ( Opposite of continuous. ... hypotenuse, then a2 b2 = c2. Proof: See next . a. b. Pythagoras of Samos (ca. ... – PowerPoint PPT presentation

Number of Views:287
Avg rating:3.0/5.0
Slides: 106
Provided by: ecsu
Category:

less

Transcript and Presenter's Notes

Title: CMPT 285 Discrete Mathematics


1
CMPT 285Discrete Mathematics
  • by Kossi Edoh
  • Department of Computer Science
  • Montclair State University

2
So, whats this class about?
  • What are discrete structures anyway?
  • Discrete (? discreet!) - Composed of
    distinct, seperable parts. (Opposite of
    continuous.) discretecontinuous
    digitalanalog
  • Structures - objects built up from simpler
    objects according to a definite pattern.
  • Discrete Mathematics - The study of discrete,
    mathematical objects and structures.

3
Discrete Structures Well Study
  • Propositions
  • Predicates
  • Sets
  • (Discrete) Functions
  • Orders of Growth
  • Algorithms
  • Integers
  • Proofs
  • Summations
  • Permutations
  • Combinations
  • Relations
  • Graphs
  • Trees

4
Relationships Between Structures
  • ? ? Can be defined in terms of

Programs
Proofs
Groups
Trees
Operators
Propositions
Complex numbers
Graphs
Real numbers
Strings
Functions
Integers
Naturalnumbers
Matrices
Relations
Sequences
Infiniteordinals
Bits
n-tuples
Vectors
Sets
5
Some Notations Well Learn

6
Why Study Discrete Math?
  • The basis of all digital information processing
    is Discrete manipulations of discrete structures
    represented in memory.
  • Its the basic language and conceptual foundation
    of all of computer science.
  • Discrete concepts are also widely used throughout
    math, science, engineering, economics, biology,
    etc.,
  • A generally useful tool for rational thought!

7
Uses for Discrete Math in Computer Science
  • Advanced algorithms data structures
  • Programming language compilers interpreters.
  • Computer networks
  • Operating systems
  • Computer architecture
  • Database management systems
  • Cryptography
  • Error correction codes
  • Graphics animation algorithms, game engines
  • Just about everything!

8
Course Outline
  • Logic (1.1-4)
  • Proof methods (1.5)
  • Set theory (1.6-7)
  • Functions (1.8)
  • Countability (3.4)
  • Algorithms (2.1)
  • Orders of Growth (2.2)
  • Complexity (2.3)
  • Number theory (2.4-6)
  • Matrices (2.7)
  • Proof strategy (3.1)
  • Sequences (3.2)
  • Summations (3.2)
  • Inductive proofs (3.3)
  • Recursion (3.4-5)
  • Combinatorics (ch. 4)
  • Probability (ch. 5)
  • Recurrences (6.1-3)
  • Relations (ch. 7)
  • Graph Theory (chs. 89)

9
Course Objectives
  • Upon completion of this course, the student
    should be able to
  • Check validity of simple logical arguments
    (proofs).
  • Check the correctness of simple algorithms.
  • Creatively construct simple valid logical
    arguments.
  • Creatively construct simple correct algorithms.
  • Describe the definitions and properties of a
    variety of specific types of discrete structures.
  • Correctly read, represent and analyze various
    types of discrete structures using standard
    notations.

Think!
10
A Proof Example
  • Theorem (Pythagorean Theorem of Euclidean
    geometry) For any real numbers a, b, and c, if a
    and b are the base-length and height of a right
    triangle, and c is the length of its hypotenuse,
    then a2 b2 c2.
  • Proof See next slide.

Pythagoras of Samos(ca. 569-475 B.C.)
b
a
11
The Proof (Graphically)
  • Proof Note a2 b2 (ab)2 - 2ab c2.

c2
½ab
½ab
½ab
b2
c
b
Areas inboldfacefont weight lengths innormal
fontweight
c
½ab
ab
b
ab
a
c
½ab
c
a2
a
½ab
½ab
½ab
ab
ab
12
Logic
  • Logic is a language for reasoning.
  • It is a collection of rules used when doing
    logical
  • reasoning
  • Types of logic
  • Propositional logic (logic of sentences)
  • logic of objects (predicate logic)
  • logic involving uncertainties
  • logic dealing with fuzziness
  • temporal logic etc.

13
Have Fun!
14
Example
  • Example Counting
  • The Traveling Salesman Problem
  • Use in
  • circuit design
  • many other CS problems
  • Given
  • n cities c1, c2, . . . , cn
  • distance between city i and j , dij
  • Find the shortest tour

15
Example continued
Choose the first city in n ways the second city
in n-1 ways the third city in n-2 ways
etc. Number of possible tours n (n-1)
(n-2) (2) (1) n! Total number of additions
(n-1)n! If 1 flop 1 nanosecond 109 sec For
n 8, T(n) 7(8!) 282240 flops lt 1/3
second For n50, T(n) 49 (50!) 4.73 x1049
years
16
Proposition
  • Proposition It involves sentences that are
    either
  • trueT (or 1) or false F (or 0) (binary logic)
  • the moon is made of green cheese
    yes
  • go to town! X imperative (command)
    no
  • What time is it? X- interrogative
    yes
  • x gt 10 need value of x
  • A proposition in general contains a number of
    variables
  • Example of propositional variables P, Q, R, S, .
    . .
  • A table of all possible relationships between a
  • proposition and its variables is called a truth
    table

17
Truth Tables
  • Logical Operators (connectives) Unary, binary
  • Unary
  • Negation, not.
  • Symbol ?
  • Example P I am going to town
  • ?P I am not going to town
  • I aint goin.
  • It is not the case that I
    am going to town
  • Truth Table p ?p
  • F(0)
    T(1)
  • T(1)
    F(0)

18
Binary operators
Conjunction and Symbol
? Disjunction, or Symbol
? Exclusive OR Symbol
? P - I am going to town Q - It is
going to rain P ? Q I am going to town
and it is going to rain P ? Q I am going to
town or it is going to rain P ? Q Either I am
going to town or it is going to rain P Q
P ? Q P ? Q P ? Q 0 0
0 0 0 0 1
0 1 1 1
0 0 1 1 1
1 1 1 0
19
Implication
ifthen Symbol
? Example P - I am going to town
Q - It is going to rain P ? Q If
I am going to town then it is going to rain P
Q P ? Q 0
0 1 0
1 1 1
0 0 1
1 1
20
Other forms of Implication
  • If P, then Q
  • P implies Q
  • If P, Q
  • P only if Q
  • P is a sufficient condition for Q
  • Q if P
  • Q whenever P
  • Q is a necessary condition for P
  • Note The implication is false only when P is
    true
  • and Q is false!

21
Terminology
P premise, hypothesis, antecedent Q
conclusion, consequences Q ? P is the converse
of P ? Q ?Q ? ? P is the contrapositive of P
?Q Find the converse and the contrapositive of
the following statement R Raining tomorrow is
a sufficient condition for my not going to
town.
22
Biconditional
if and only if , iff Symbol
? P - I am going to town Q - It is going to
rain P ? Q I am going to town if and only if
it is going to rain. P
Q P ? Q 0 0
1 0 1
0 1 0 0
1 1 1 Note
Both P and Q must have the same value Other
binary operators NAND ( ) NOR (?)
23
Example
If I go to Harrys or go to the country then I
will not go shopping. P I go to Harrys Q I
go to country R I will go shopping (P ? Q) ?
?R Note A truth table with n propositional
variables has - 2n rows
24
Example continued
P Q R (P ? Q)? ?R 0 0
0 1 0 0 1
1 0 1 0 1 0
1 1 0 1 0
0 1 1 0 1
0 1 1 0 1 1
1 1 0 Question How
many different propositions can be constructed
from n propositional variables?
25
Section 1.2 Propositional Equivalence
A tautology is a proposition which is always
true Example P ? ?P A contradiction is a
proposition which is always false Example
P ? ?P A contingency is a proposition which is
neither a tautology nor a contradiction. Example
(P ? Q) ? ?R Compound propositions with the
same truth values in all possible cases are
called logically equivalent
26
Logical equivalence
Example Show that the proposition ?P ? Q and P
? Q are logically equivalent P Q
?P ? Q P ? Q 0 0 1
1 0 1 1
1 1 0 0 0 1
1 1 1 P and Q are
logically equivalent if P ? Q is a tautology. We
write P ? Q
27
Logical equivalence
Example (P ? Q) ? (Q ? P) ? (P ??? Q) Proof
Show that the proposition is not a tautology
- find a counter example or disprove the
assertion - search for a case where the
proposition is false Case 1 LHS F Only one
of P?Q or Q?P is false Assume P?Q F. Then PT,
QF, RHS P?Q F?? Assume Q?P F. Then QT, PF,
RHS P?Q F?? Case 2 RHS F Assume P T, Q
F, LHS cannot be true Assume Q T, P F, LHS
cannot be true
28
List of Logical Equivalence
P ? T ? P
Identity P ? F ? P P ? T ? T
Domination P ? F ? F P ? P ? P
Idempotency P ? P ? P (?( ?P)) ? P
Double Negation P ? Q ? Q ? P P ? Q ? Q ?
P Commutativity (P ? Q) ? R ? P ? (Q ?
R) (P ? Q) ? R ? P ? (Q ? R)
Associativity (P ? Q) ? (?Q ? ?P)
Contrapositive
29
List continued
P ? (Q ? R ) ? (P ? Q) ? (P ? R )
Distributivity P ? (Q ? R ) ? (P ? Q) ? (P ?
R) ?(P ? Q) ? ?P ? ?Q
DeMorgans Laws ?(P ? Q) ? ?P ? ?Q P ? Q ? ?P ?
Q Implication P ? ?P ?
F Tautology P
? ?P ? T Contradiction P ? T ? P, P ?
T ? P (P ? Q) ? (Q ? P) ? (P???Q)
Equivalence (P ? Q) ? (P ? ?Q) ? ?P
Absurdity P ? (P ? Q) ?P, P? (P? Q)? P
Absorption (P ? Q) ? R ? P ? (Q ? R)
Exportation
30
Example
  • Example Show that (P ? Q) ? (P ? Q) is a
    tautology
  • (p ? q)?(p ? q) ? ?(p ? q) ? (p ? q)
  • ? (?p ? ?q) ? (p ? q) De
    Morgans Law
  • ? (?p ? p) ? (? q ? q)
  • ? T ? T
  • ? T

31
Section 1.3,1.4 Predicates and Quantifiers
Propositional functions or predicates are
propositions which contain variables Example Let
P denote the Predicate is greater than 0
and P(x) denote x gt 0
x is called a variable The predicate become a
proposition once the variable x has been
assigned a value. Example What is the
truth value of p(5), p(0) and p(-2)?
5gt0 is true, 0gt0 is false and
-2gt0 is false
32
Examples
Example Let Q(x,y) denote the statement
y x 2. What is the truth value of
Q(2,4,) and Q(4, 1) 4 22 is
true and 1 42 is false Q(2,y) ? ?Q(0,3) is
not a proposition y is not bounded Q(1,3) ?
?Q(0,1) is a proposition which is true
33
Universe of Discourse
Question Let R be the three-variable predicate
R(x,y,z) xy z
Find the truth value of R(2,-1,5),
R(3,4,7) R(x,3,z) A universe
of discourse (U) is a domain for the variables
of a propositional function. Example Let U Z,
the integers , -2, -1, 0, 1, 2,
34
Universal quantifier
The Universal Quantifier of P(x) is the
proposition P(x) is true for every x in the
universe of discourse Notation ?x P(x)
For all x, P(x) For every x,
P(x) Example U 1, 2, 3 ?x P(x) ?
P(1) ? P(2) ? P(3) Example What is the truth
value of ?x P(x) if P(x) is 3x lt10and U is
positive integers not exceeding 4
P(1) ? P(2) ? P(3) ? P(4) is false
35
Existential quantifier
The Existential Quantifier of P(x) is the
proposition P(x) is true for some x in the
universe of discourse Notation ?x
P(x) For some x P(x) For at least
an x in P(x) Example U 1, 2, 3, ?x
P(x) ? P(1) ? P(2) ? P(3) Example What is the
truth value of ?x P(x) if P(x) is 3x lt10and U
is positive integers not exceeding 4
P(1) ? P(2) ? P(3) ? P(4) is True
36
Unique Existence
The Unique Existence quantifier of P(x) is the
proposition P(x) is true for one and only one
x in the universe of discourse. Notation
?!x P(x) There is a unique x such that
P(x) One can find only one x such that P(x)
37
Example
U 1, 2, 3 P(1) P(2) P(3)
?!x P(x) 0 0 0 0 0
0 1 1 0 1 0 1 0 1
1 0 1 0 0 1 1 0
1 0 1 1 0
0 1 1 1 0
38
Translate into English
Example Translate the statement
?x(C(x) ? ?y(C(y) ?F(x,y))) into
English Where C(x) is x has a computer
F(x,y) is x and y are friends a and U is x
and y are students in your school For every
student x in your school x has a computer or
there is a student y such that y has a computer
and x and y are friends.
39
Example
ExampleLet U R, the real numbers. P(x,y) xy
0 ?x?y P(x,y) False ?x ?y
P(x,y) True ?x ?y P(x,y)
True ?x ?y P(x,y) True Example
Let U 1, 2, 3. Find an expression equivalent
to ?x ?y P(x,y) where the variables are bound by
substitution instead Solution ?y P(1,y) ? ?y
P(2,y) ? ?y P(3,y) ? P(1,1) ?
P(1,2) ? P(1,3) ? P(2,1) ?
P(2,2) ? P(2,3) ? P(3,1) ?
P(3,2) ? P(3,3)
40
Converting from English
Examples F(x) x is a fleegle
S(x) x is a snurd
T(x) x is a thingamabob U fleegles, snurds,
thingamabobs Everything is a fleegle
?x F(x) ? ??x?F(x) Nothing is a snurd
?x ?S(x) ? ??x S(x) All fleegles are
snurds ?x F(x) ? S(x) Some
fleeges are thingamabobs ?xF(x) ? T(x)
No snurd is a thingamabob ?xS(x) ?
?T(x) If any fleege is a snurd then its also a
thingamabob ?x (F(x) ?
S(x)) ? T(x)
41
Negation
Equivalence involving the negation operator
??x P(x) ? ?x ?P(x) ??x
P(x) ? ?x ?P(x) Multiple Quantifiers read from
left to right See page 31
42
Section 1.5 Method of proof
  • Learn to proof the validity of Mathematical
  • arguments
  • 2) Learn the tools needed for
  • program verification (ie. The formal
    technique to
  • verify that procedures are correct)
  • establishing operating system security
  • making inference in artificial intelligence

43
Introduction
A theorem is a valid logical assertion which can
be proved using a) other theorems b)
axioms (statements given to be true) c)
rules of inference (logical rules which allow
the deduction of conclusions from
premises) A lemma is a result which is needed to
prove a theorem A corollary is a result which
follows from a theorem A conjecture is a
statement whose truth value is unknown

44
Rules of inference
Steps used to show that a conclusion follows
logically from a set of hypothesis Many
tautologies are rules of inference and of the
form H1? H2 ? H3 ? ? Hn ? C, Hi are called
the hypothesis. C is the conclusion. As a
rule of inference they take the symbolic
form H1, H2, H3, , Hn ? C
45
Example
  • The tautology P ? (P ? Q) ? Q symbolic form
  • P, P ? Q ? Q
  • This rule of inference is known as
  • modus ponens or
  • the law of detachment

46
Example cont.
Example The implication if n is divisible by
3, then n2 is divisible by 9, is true. (P?
Q) Consequently if n is divisible by 3, (P) then
by modes ponens, it follows that n2 is divisible
by 9 (Q)

47
Examples
Example If it rains today, then we will not have
a barbeque today. If we do not have barbecue
today, then we will have a barbecue tomorrow.
Therefore, if it rains today then we will have a
barbecue tomorrow. Solution Let p be It is
raining today q be we
will not have barbecue today
r be we will have barbecue tomorrow
Argument is p ? q
q ? r -----------
? p ? r
48
Other rules of inference
P ? P ? Q
Addition P ? Q ? P
Simplification P, P ? Q
? Q Modus Ponens ?Q, P ? Q
? ?P Modus Tollens P ? Q, Q ? R
? P ? R Hypothetical Syllogism P ? Q, ?P
? Q Disjunctive
Syllogism P, Q ? P ?
Q Conjunction (P?Q)?(R?S), P?R ? Q?S
Constructive Dilemma
49
Formal Proofs
  • To prove an argument is valid or the conclusion
    follows
  • logically from the hypotheses
  • Assume the hypotheses are true
  • Use the rules of inference and logical
    equivalences
  • to determine that the conclusion is true

Example Consider the following logical
statements If horses fly or cows eat
artichokes, then the mosquito is the national
bird. If the mosquito is the national bird then
peanut butter tastes good on hot dogs. But
peanut butter tastes terrible on hot dogs.
Therefore, cows dont eat artichokes.
50
Example continued
Solution Assign propositional variables to the
component propositions in the argument
F Horses fly A Cows
eat artichokes M The mosquito is
the national bird P Peanut
butter tastes good on hot dogs Represent the
formal argument using the variables
1. (F ? A) ? M 2. M ?P
3. P ? A
51
Proof
Assertion Reason 1. (F? A) ? M
Hypothesis 1. 2. M ? P
Hypothesis 2. 3. (F ? A) ? P Steps 1 and 2
and hypothetical syll. 4. ?P
Hypothesis 3. 5. ?(F? A) Steps 3 and
4 and modus tollens 6. ?F ??A Steps
5 and De Morgan 7. ?A ?? F Steps 6
and commutativity of and 8. ??A
Steps 7 and simplification
52
Rules of inference for quantifiers
  • ?x P(x) ? P(c) if c ? U
    Univ Instan
  • P(c) for an arb c ? U ? ?x P(x)
    Univ Gener
  • P(c) for some ele c ? U ? ?x P(x)
    Exist Gener
  • ?x P(x) ? P(c) for some ele c ? U
    Exist Instan
  • In Universal Generalization, x must be arbitrary
  • In Universal Instantiation, c need not be
    arbitrary
  • but often is assumed to be.
  • In Existential Instantiation, c must be an
    element
  • of the universe which makes P(x) true.

53
Example
Every man has two legs, John Smith is a
man. Therefore, John Smith has two
legs. Predicates M(x) x is a man
L(x) x has two legs J
John Smith is a member of the universe 1.
?xM(x) ? L(x) 2. M(J) ?L(J) Proof
1. ?xM(x) ? L(x) Hypothesis 1
2. M(J) ? L(J) Step 1 and UI
3. M(J) Hypothesis 2
4. L(J) Step 2
and 3 and modus
ponens
54
Fallacies
  • Fallacies are incorrect inferences.
  • The fallacies of Affirming the Consequent
  • Example If the butler did it he has blood on
    his hands.
  • The butler has blood on his hands
  • Therefore, the butler did it.
  • P? Q, Q ? P or (P?
    Q) ?Q ?P
  • The fallacy of Denying the Antecedent
  • Example If the butler is nervous, he did it
  • The butler is really mellow.
  • Therefore, the butler didnt
    do it.
  • P ?Q, P ? Q or
    (P?Q)?P?Q

55
Example
  • Begging the question or circular reasoning(using
  • itself)
  • Example If x2 is even then x is even.
  • Proof
  • If x2 is even then x2 2k for some k,
    Let x 2m
  • for some integer m, Hence, x must be
    even.
  • The statement let x 2m for some integer m has
  • not been shown to be correct. This is circular
  • reasoning

56
Methods of Proof
We wish to establish the truth of the theorem
P ? Q P may be a
conjunction of other hypotheses. P ? Q is a
conjecture until a proof is produced Trivial
proof If we know Q is true then P?Q is
true. Example If its raining today then
the void set is a subset
of every set. The assertion is trivially true
independent of the truth of P.
57
Vacuous and Direct Proof
Vacuous proof If we know one of the
hypotheses in P is false then P ? Q is vacuously
true. Example If I am both rich and poor then
hurricane Fran is a mild breeze.
(P ?P) ? Q and the hypotheses form a
contradiction. Direct proof - assume
the hypotheses are true - uses the rules
of inference, axioms and any logical
equivalence to establish the truth of the
conclusion
58
Indirect Proof
A direct proof of the contrapositive -
assume the conclusion of P?Q is false (Q is
true) - uses the rules of inference, axioms
and any logical equivalences to establish
the premise P is false. Note, in order to show
that a conjunction of hypotheses is false is
suffice to show just one of the hypotheses is
false. Example if 6x 9y 101, then x or y is
not an integer. Proof (Direct) Assume 6x
9y 101 is true. 2x 3y 101/3. Either 2x
or 3y is not integer (both) Therefore, one of
x or y must not be an integer.
59
Proof by contradiction
It - assume the conclusion Q is false -
derives a contradiction, usually of the form P?P
which establishes Q?0. The contrapositive of
this assertion is 1?Q from which it follows that
Q must be true. Theorem There is no largest
prime number. Proof We assume the conclusion
there is no largest prime number is false.
There is a largest prime number. call it P.
Hence, the set of all primes lie between 1 and
p. Let r 2.3.5.7.11..p. But r1 is a prime
larger than p.
60
Proof by cases
  • Break the premise of P?Q into an equivalent
    disjunction
  • of the form
  • P1?P2?? Pn
  • Then use the tautology
  • (P1?Q)?(P2?Q)??(Pn?Q) ? (P1?P2??Pn)?Q
  • Each of the implications Pi ? Q is a case.
  • You must
  • convince the reader that the cases are
    inclusive,
  • i.e., they exhaust all possibilities.
  • establish all implications.

61
Example
Let ? be the operation max on the set of
integers if a ? b then a?b max a,
b a b?a Theorem The operation ? is
associative. For all a, b, c (a?b)?c
a?(b?c). Proof Let a, b, c be arbitrary
integers. Then the following six cases must hold
(are exhaustive) 1) a?b?c 2)
a?c?b 3) b?a?c 4) b?c?a
5) c?a?b 6) c?b?a Case 1 a?b
a, a?c a, and b?c b Hence (a?b)?c a
a?(b?c) (rest for students)
62
Existence Proofs
Constructive existence proofs We wish to
establish the truth of ?x
P(x) -Establish P(c ) is true for some c in the
universe. -Then ?xP(x) is true by Existential
Generalization. Theorem There exists a bijection
from A0,1 to B0,2 Proof Let f be the
identity map from A to B. Then f is an injection
(and we conclude that A ? B) Define the
function g from B to A as g(x) x/4. Then g is
an injection. Therefore, B ? A Therefore
AB, hence there must be a bijection A to B
63
Non-constructive existence proof
It -Assume no c exists which makes P(c ) true
and derive a contradiction. Theorem There
exists an irrational number. Proof Assume
there doesnt exist an irrational number.
Then all numbers be irrational. Then the set of
all numbers must be countable. Then the real
numbers in the interval 0,1 is a countable set
which is false. Therefore there must exist an
irrational number.
64
Universally Quantified Assertion
We wish to establish the truth of
?x P(x) We assume that x is an
arbitrary member of the Universe and show P(x)
must be true. Using UG it follows that
?x P(x) Theorem For the universe of integers,
x is even iff x2 is even Proof The quantified
assertion is ?x x is even ?
x2 is even Recall that P?Q is equivalent to
(P?Q)?(Q ?P).
65
Proof continued
Case 1. If x is even then x2k for some integer
k. Hence, x2 4k2 2(2k2) which is even since
it is divisible by 2. Case 2. We show that if
x2 is even then x must be even. Use an indirect
proof Assume x is not even and show x2 is not
even. x 2k 1 for some k. Then x2 (2k1)2
4k2 4k 1 2(2k2 2k)1 which is odd and
hence not even.
66
3.3 Induction
  • Definition A set S is well ordered if every
    subset has
  • a least element.
  • Note 0,1 is not well ordered since (0,1 does
    not
  • have a least element.
  • Example
  • N is well ordered (under ? the relation)
  • Any countably infinite set can be well ordered
  • Z can be well ordered but it is not well ordered
  • under the ? relation
  • The set of finite strings over an alphabet using
  • lexicographic ordering is well ordered

67
First principle of mathematical induction
  • It has the form.
  • P(1), P(n) ? P(n1) ? ?n P(n)
  • The hypothesis are
  • H1 P(1)
  • H2 P(n)?P(n1) for n arbitrary
  • H1 is called The Basis Step.
  • H2 is called The Induction (Inductive) Step

68
Example
Prove that the sum of the first n odd positive
integers is n2 Proof 1 3 5 7
(2n-1) n2 Basic step 1 12 Inductive
step suppose 1 3 5 7
(2n-1) n2 then 1 2 3 4 (2n-1)
(2n1) n2 (2n 1)
(n 1)2
69
Example
Prove that 2n lt n! for every positive integer n
? 4 Proof Basic step 24 16 lt 4! 24
Inductive step
Assume 2n lt n! then
2n1 2. 2n lt 2 n!
lt (n1) n!
(n 1) !
70
The Second principle of Mathematical Induction
The rule of inference becomes H1
P(0) H2 P(0) ? P(1) ? ? P(n) ?
P(n1) ? ?n P(n) The two rules are
equivalent but sometimes the second is easier to
apply.
71
Example
Show that if n is an integer greater than 1, then
n can be written as the product of primes. Let
P(n) be n can be written as a product of
primes Basic Step P(2) 2 Inductive
Step Assume P(k) is true for all 2 lt k ? n
if n1 is a prime then P(n1) is true
if n1 ab 0 ? a ? b lt n1 then a
and b are product of primes by the
induction hypothesis
72
3.4 Recursive Definitions
  • Recursive or inductive definitions of sets and
    functions.
  • (Note recursively defined sets are similar.)
  • Basic step
  • For sets- State the basic building blocks of the
    set.
  • For functions- State the values of the function
  • on a basic building block.
  • Inductive or recursive step
  • For sets- Show how to build new things from old
  • with some construction rules.
  • For functions- Show how to compute the values of
  • a function on the new things from the
    old.

R
73
Example
  • Example f(0) 3
  • f(n1) 2f(n) 3
  • f(1) 2f(0) 3
    9
  • f(2) 2f(1) 3
    21
  • Example
  • The factorial function f(n) n! can be defined
    as
  • f(0) 1
  • f(n1) (n 1) f(n)
  • f(1) 1 f(0) 1
  • f(2) 2 f(1) 2

74
Example
The Fibonacci numbers f0, f1, f2, are defined
by the equations f0 0 f1 1
fn fn-2 fn-1 f2 f0 f1 0 1 1 f3
f1 f2 1 1 2
75
Example on sets
Example The well-formed formulae of variables,
numerals, and operators from , -, , /, ?
(where ? denotes exponentiation) are defined by
x is well-formed formulae if x is a numeral or a
variable (fg), (f-g), (fg), (f/g), and (f?g)
are well-formed formulae if f and g are. Since
x, y and 3 are well-formed formulae, (x3),
(x-3), (x3), (x/3), (x?3) are well-formed
formulae. So also is ((x3)-y)
76
Example on sets
Example A recursive definition of the set of
strings over a finite alphabet ?. The set of
all strings (including the empty set or null
string ?) is called (the monoid)
? Basic The empty string ? ?
? Induction If w ? ? and a ? ?, then wa ?
? Note we can concatenate a on the right or
left, but it makes a difference in proofs since
concatenation is not commutative
77
Extra Definitions continued
Commutativity ?x?y P(x,y) ? ?y?x P(x,y)
True ?x?y P(x,y) ? ?y?x P(x,y) False Check
for distributivity Let X be a proposition
involving only ?, ?, and ? then X the dual of X
is X with ?, ? , T and F replaced by ?, ?, F and
T respectively.
78
Section 1.6 Sets
  • A Set is a collection or group of objects or
    elements or
  • members. (Cantor 1895)
  • A set is said to contain its elements
  • There must be an underlying universal set U,
  • either specifically stated or understood.
  • Notation.
  • list the elements between braces S a, b,
    c,d.
  • specification by predicates S x P(x)
  • brace notation with ellipses S , -3,-2,-1

79
Common Universal Sets
R Real numbers N natural numbers 0, 1, 2,
3, Z all integers , -3, -2, -1, 0, 1,
2, Z set of all positive integers Notation
x is a member of S x ? S x is not a
member of S x ? S The set A is a subset
of the set B A ? B
?xx ?A ? x ?B The void, null, empty set ? It
has no members
80
Subsets
x ? ? is always false
?xx ? ? ? x ? B Therefore ? is a subset of
every set A set B is always a
subset of itself. If A ? B but A ? B then A is a
proper subset of B, A?B The set of all subset of
a set A, denoted P(A) is called the power set of
A Example If A a, b , B ?
,? then P(A)?, a, b, a,b
P(B)?, ?, ?, ?,?
81
Cardinality
The number of distinct elements in A, denoted A
is called the cardinality of A If the
cardinality is a natural number (in N), then the
set is called finite, else infinite Example A
a, b a,b 2 P(a,
b) 4 A n implies P(A) 2n N is
infinite since N is not a natural number. It is
called transfinite cardinal number. Note Sets
can be both members and subsets of other set
82
Cartesian product
The Cartesian product of A with B, denoted A x B,
is a set of ordered pairs lta,bgt a ?A ?
b ?B n Notation X Ai
lta1, a2, , angt ai ? Ai i
1 The Cartesian product of anything with ? is ?
(why?) Example A a,b B 1, 2, 3 A x B
lta,1gt, lta,2gt lta,3gt, ltb,1gt ltb,2gt ,ltb,3gt What is
B x A, A x B x A? If A m and B n, what
is A x B?
83
Section 1.6 Set Operations
  • Propositional calculus and set theory are both
  • instances of an algebraic system called a
  • Boolean Algebra
  • Two sets A and B are equal, denoted A B iff
  • ?xx ? A ? x ? B
  • ?x(x ? A ? x ? B) ? (x ? B? x ? A)
  • A ? B and B ? A
  • The union of A and B, denoted A ? B is the set
  • x x ? A ? x ? B
  • The intersection of A and B, denoted A ? B is
    the set
  • x x ? A ? x ? B

84
Definitions
If the intersection is void then A and B are
disjoint The compliment of A, denoted A or Ac
x ?(x ?
A) The difference of A and B, or the complement
of B relative to A, denoted A B, is the set
A ? Bc The absolute compliment of A is U
A The symmetric difference of A and B is denoted
A ? B (A B) ? (B A)
85
Example
  • U 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
  • A 1, 2, 3, 4, 5, B 4, 5, 6,
    7, 8. Then
  • A ? B 1, 2, 3, 4, 5, 6, 7, 8
  • A ? B 4, 5
  • A 0, 6, 7, 8, 9, 10
  • Bc 0, 1, 2, 3, 9, 10
  • A B 1, 2, 3
  • B A 6, 7, 8
  • A ? B 1, 2, 3, 6, 7,8

86
Venn Diagrams and Set Identity
Venn Diagram A visualization tool (for 3 or less
sets)
A
U
B
87
Set Identity
(A ? B)c Ac ? Bc Check proof !
88
Set Identity continued
Let A1 , A2 , A3, , An be an indexed collection
of sets. Because union and intersection are
associative n U Ai A1 ? A2 ? ? An and
i1 n ? A i A1 ? A2 ? ... ? An i1 Example
Let Ai i, ?), 1? i lt ? n
n U Ai 1, ?)
and ? A I n, ?) i1
i1
89
Section 1.8 Functions
Let A and B be sets. A function f from A to B,
denoted f A ? B, is a subset of A x B such that
?x x ? A ? ?y y?B ? ltx,ygt ? f and
ltx,y1gt ? f ? ltx, y2gt ? f ? y1 y2 f
associates with each x in A one and only one y in
B. A is called the domain
B is called the codomain Assume
f(x) y y is called the image of x under
f x is called a preimage of y
90
Functions continued
  • The range of f is the set of all images of points
    in A
  • under f. We denote it by f(A)
  • If S is a subset of A then
  • f(S) f(s) s in S
    A B
  • f(a) Z
    a o o X
  • the image of d is Z
    b o o Y
  • the domain of f is A a,b,c,d c o
    o Z
  • the codomain is B X, Y, Z d o
  • the preimage of Y is b
  • the preimages of Z are a, c and d
  • f(c,d) Z

91
Definitions
f is one-to-one or injective if preimages are
unique. If a ? b then f(a) ?
f(b) f is onto or surjective if every y in B has
a preimage. For every y in B there must be an x
in A s.t. f(x) y. f is bijective if it is
surjective and injective A B
A B a
o o X a o
o V b o o Y
b o o W c o
o Z c o
o X d o
d o o Y Surjection but not
injection o Z

Injection but not surjection
92
Cardinality
  • Whenever there is a bijection from A to B, the
    two sets
  • must have the same number of elements or
    cardinality
  • Let A B R, the reals. Determine which are
  • injections, surjections, bijections
  • f(x) x
  • f(x) x 2
  • f(x) x 3
  • f(x) x sin(x)
  • f(x) x
  • Let E be the set of even integers 0, 2, 4,
  • f(x) 2x is a bijection from N to E. Both E and
    N have
  • the same cardinality.

93
Examples
A B a o
o V Surjection and an injection,
b o o W hence a bijection
c o o X d o o Y Whenever
there is a bijection from A to B, the two
sets must have the same number of elements or the
same
cardinality That will become our definition,
especially for finite sets.
94
Inverse Functions
Let f be a bijection from A to B. Then the
inverse of f, denoted f1, is the function from B
to A defined as f1 (y) x iff
f(x) y Example A f ? B
A? f1 B a o o V
a o o V b o o W
b o o W c o
o X c o o
X d o o Y d o
o Y Let S be a subset of B.
Then f1 (S) x f(x) ? S
95
Composition
Let f B ? C, g A ? B. The composition of f with
g, denoted f o g, is the function from A to C
defined by fog(x) f(g(x))
A g B f
C a o o V
o h b o o W
o i c o o X
o j d o
o Y A f o g
C a o o h
b o o i
c o o j d o

96
Definition
The floor function is denoted f(x) ?x? or f(x)
floor(x), is the largest integer less than
x. The ceiling function denoted f(x) ?x? or
f(x) ceiling(x), is the smallest integer
greater than or equal to x. Example
?3.9? 3, and ?3.9? 4
97
Section 2.2 Growth functions
  • The concept that g grows at least as fast as f.
  • In comparing the complexity of algorithms
  • We only care about the behaviour for large n
  • Even bad algorithms can be used to solve small
  • Ignore implementation details such as loop
  • counter problems incrementation, etc.

98
The big O notation
The Big-O Notation Definition
Let f and g be functions from N to R. Then g
grows asymptotically and dominates f, denoted
f is O(g) or
f is big-O of g, or
f is of order g, iff ?k ?C ?n
n gt k ? f(n) ? Cg(n)
99
Example
Example Show that f(x) 2x2 3x 1 is
O(x2) 0 ? 2x2 3x 1 lt 2x2 3x2 x2 6x2
whenever x gt 1 with C 6. Note the value of k
and C is not unique Example 7x2 is O(x3)
with k 7 and C 1
100
Little o
  • f(n)
  • If lim ----- 0 then f is o(g) (called little-o
    of g)
  • n?? g(n)
  • Theorem If f is o(g) then f is O(g)
  • It is usually easier to prove f is o(g)
  • using the theory of limits
  • using LHospitals rule
  • using the properties of logarithms
  • etc.

Example 3n 5 is O(n2). Lim (3n5)/n2 0 Hence
3n 5 is o(n2) and so it is O(n2)
101
Complexity class
  • Note that O(g) is a set called a complexity
    class.
  • It contains all the functions which g dominates
  • Theorem f is o(g) means f ? O(g)
  • Properties of Big O
  • f is O(g) iff O(f) ? O(g)
  • if f is O(g) and g is O(f) then O(f) O(g)
  • the set O(g) is closed under addition
  • the set O(g) is closed under multiplication by
    a scalar
  • if f is O(g) and g is O(h), then f is O(h)

102
Important Complexity Classes
  • O(1) ? O(log n) ? O(n) ? O(n log n) ? O(n2)
  • O(nj) ? O(cn) ? O(n!) where j gt 2 and c gt 1.
  • Suppose that f1(x) is O(g1(x)) and f2(x) is
    O(g2(x)).
  • Then (f1 f2)(x) is O(max(g1(x),g2(x))
  • (f1f2)(x) is O(g1(x)g2(x))

103
Examples
Example Suppose algorithm 1 has complexity n2
n 1 algorithm 2 has
complexity n2/2 3n 2 then both are O(n2).
Algorithm 2 has a smaller leading coefficient
and will be faster for large problems. Hence we
write Algorithm 1 has complexity n2
O(n) Algorithm 2 has complexity n2/2 O(n)
104
Example
  • Example Find the complexity class of the
    function
  • (n n! 3n2 3n100)(nn n2n)
  • Solution
  • This means to simplify the expression
  • Throw out stuff which you does not grow fast
  • Eliminate 3n2 and 3n100 since they grow
    slower
  • than n!
  • Eliminate n2n since it grows slower than
    nn
  • Hence the complexity class is O(n n! nn)

105
Big Omega and Theta
f(x) is ?(g(x)) if the are positive constants C
and k such that f(x) ?C g(x) whenever
x gt k. f(x) is ?(g(x)) if f(x) is ?(g(x)) and
f(x) is O(g(x)) and we say f(x) is of order
g(x).
Write a Comment
User Comments (0)
About PowerShow.com