0% found this document useful (0 votes)
27 views

Unit 3 MI

This document describes a course in discrete mathematics. It covers topics like logic, proofs, sets, functions, sequences, mathematical induction, and recursion. It provides learning outcomes, course contents organized by units, textbook recommendations, and examples of applying concepts like proving identities and properties using induction.

Uploaded by

sharvarictamane
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views

Unit 3 MI

This document describes a course in discrete mathematics. It covers topics like logic, proofs, sets, functions, sequences, mathematical induction, and recursion. It provides learning outcomes, course contents organized by units, textbook recommendations, and examples of applying concepts like proving identities and properties using induction.

Uploaded by

sharvarictamane
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 103

Discrete Mathematics

Course Code: 0UIT404D, Course Type: Compulsory


L – T – P: 3– 0 – 0
Stream: Core, Credits: 3

Prepared By: Dr S C Tamane


Course Outcomes
After learning the course, the students should be able to
1. Verify the correctness of an argument using symbolic logic and truth
tables.
2. Construct mathematical arguments using logical connectives and
quantifiers.
3. Construct proofs using mathematical induction And Solve problems
involving recurrence relations and generating functions
4. Perform operations on discrete structures such as sets, functions,
relations
5. Solve problems using counting techniques on sets and also find
probability
Contents
• Unit 3: Sequences, Mathematical Induction, and Recursion
• Sequences, Mathematical Induction, Strong Mathematical Induction
and the Well-Ordering Principle for the Integers, Application:
Correctness of Algorithms.
• Defining Sequences Recursively, Solving Recurrence Relations by
Iteration, Second-Order Linear Homogenous Recurrence Relations
with Constant Coefficients, General Recursive Definitions and
Structural Induction
• (Chapter 5: Sequences, Mathematical Induction, and Recursion from
Susanna S. Epp, “Discrete Mathematics with Applications” 4th
Edition)
Books
• Text Books:
1. Susanna S. Epp, “Discrete Mathematics with Applications” 4th
Edition.
2. K. H. Rosen, “Discrete Mathematics and Its Applications”, Tata
McGraw Hill Publication, 7 th Edition, 2012.
3. B. Kolman, R. Busby, S. Ross, “Discrete Mathematical Structures”,
Pearson Education, 6 th Edition, 2009.
4. R. K. Bisht, H. S. Dhami, “Discrete Mathematics”, Oxford University
Press, 2015.
Books
• Reference Books:
1. Kenneth H Rosen, “Discrete Mathematics and its Applications”.
2. C L Liu, “Elements of Discrete Mathematics”.
3. Norman L Biggs, “Discrete Mathematics”.
4. Kenneth Bogart and Robert L Drysdale, “Discrete Mathematics for
Computer Science”.
5. R Krishna Kumar, “Discrete Mathematics”.

• E-sources:
NPTEL course on Discrete Mathematics.
Principle of Mathematical Induction
• Let P(n) be a property that is defined for integers n,
and let a be a fixed integer.
• Suppose the following two statements are true:
• 1. P(a) is true.
• 2. For all integers k ≥ a, if P(k) is true then P(k + 1) is true.
• Then the statement
• for all integers n ≥ a, P(n)
• is true.
Method of Proof by Mathematical Induction
• Consider a statement of the form, “For all integers n ≥ a, a property P(n) is
true.”
• To prove such a statement, perform the following two steps:
• Step 1 (basis step): Show that P(a) is true.
• Step 2 (inductive step): Show that for all integers k ≥ a, if P(k) is true then
P(k + 1) is true. To perform this step,
• suppose that P(k) is true, where k is any particular but arbitrarily chosen
integer with k ≥ a.
• [This supposition is called the inductive hypothesis.]
• Then
• show that P(k + 1) is true.
Sum of the First n Integers
• Use mathematical induction to prove that

first identify the property P(n):

• show that the property is true for n = 1, or, P(1) is true


• P(1) is obtained by substituting 1 in place of n in P(n).
• The LHS of P(1) is the sum of all the successive integers starting at 1 and
ending at 1.
• This is just 1.
Sum of the First n Integers
• Thus P(1) is:

•this equation is true because the right-hand side is​

•which equals the left-hand side.​


Sum of the First n Integers
• In the inductive step, you assume that P(k) is true, for a particular but
arbitrarily chosen integer k with k ≥ 1. [This assumption is the inductive
hypothesis.]
• Show that P(k + 1) is true.
• What are P(k) and P(k + 1)? P(k) is obtained by substituting k for every n in
P(n). Thus P(k) is:

• Similarly, P(k + 1) is obtained by substituting the quantity (k + 1) for every n


that appears in P(n).
Sum of the First n Integers
• Thus P(k + 1) is:

Now show that P(k + 1) is true.


The LHS of P(k + 1) is 1 + 2+· · ·+(k + 1),
which equals
(1 + 2+· · ·+k) + (k + 1)

But by substitution from the inductive hypothesis,


Sum of the First n Integers
Now the RHS of P(k + 1) is

Thus the two sides of P(k + 1) are


equal to each other, and so the
equation P(k + 1) is true.

This is LHS.
Definition: Closed Form

If a sum with a variable number of terms is shown to be equal


to a formula that does not contain either an ellipsis or a
summation symbol, we say that it is written in closed form.
Applying the Formula for the Sum of the
First n Integers
Applying the Formula for the Sum of the First n Integers
a. Evaluate 2 + 4 + 6+· · ·+500.
b. Evaluate 5 + 6 + 7 + 8+· · ·+50.
c. For an integer h ≥ 2, write 1 + 2 + 3+· · ·+(h − 1) in closed
form.
Applying the Formula for the Sum of the
First n Integers
Solution:
Applying the Formula for the Sum of the
First n Integers
Solution:
Applying the Formula for the Sum of the
First n Integers
Solution:
Sum of a Geometric Sequence

Solution:
In this example the property P(n) is again an equation, although in
this case it contains a real variable r :.
Exercise 5.2, 3
Exercise 5.2, 3
Exercise 5.2, 3
Exercise 5.2, 3
Exercise 5.2, 3
Exercise 5.2, 4
Exercise 5.2, 4
Exercise 5.2, 4
Exercise 5.2, 4
Exercise 5.2, 4
Exercise 5.2, 4
Exercise 5.2, 4
Exercise 5.2, 6. Prove by MI
Exercise 5.2, 6. Prove by MI
Exercise 5.2, 6. Prove by MI
Exercise 5.2, 6. Prove by MI
Exercise 5.2, 7. Prove by MI
Exercise 5.2, 12. Prove by MI
Exercise 5.2, 12. Prove by MI
Use the formula for the sum of the first n integers and/or the formula
for the sum of a geometric sequence to evaluate the sums in 20 and 26
or to write them in closed form.
20. 4 + 8 + 12 + 16+· · ·+200
26. 3 + 32 + 33 +· · ·+3n, where n is an integer with n ≥ 1
Mathematical Induction II
• Proving a Divisibility Property
• Use mathematical induction to prove that for all integers n ≥ 0, 2 2n − 1 is divisible
by 3.
• Solution
• P(n) is the sentence
• 22n − 1 is divisible by 3. ←the property (P(n))
• By substitution, the statement for the basis step, P(0), is
• 22·0 − 1 is divisible by 3. ←basis (P(0))
• The supposition for the inductive step, P(k), is
• 22k − 1 is divisible by 3, ←inductive hypothesis (P(k))
• P(k + 1), is
• 22(k+1) − 1 is divisible by 3 ←(P(k + 1))
Mathematical Induction II
• Proving an Inequality
• Use mathematical induction to prove that For all integers n ≥ 3, 2n + 1 < 2n.
• Solution
• Let the property P(n) be the inequality
• 2n + 1 < 2n. ←the property (P(n))
• By substitution, the statement for the basis step, P(3), is
• 2·3 + 1 < 23. ←basis (P(3))
• The supposition for the inductive step, P(k), is
• 2k + 1 < 2k, ←inductive hypothesis (P(k))
• P(k + 1), is
• 2(k + 1) + 1 < 2(k+1) = 2k + 3 < 2(k+1).← (P(k + 1))
Mathematical Induction II
• Proving a Property of a Sequence
• Define a sequence a1, a2, a3, . . . as follows.
• a1 = 2
• ak = 5ak−1 for all integers k ≥ 2.
• a. Write the first four terms of the sequence.
• b. It is claimed that for each integer n ≥ 0, the nth term of the sequence
has the same value as that given by the formula 2·5 n −1
• In other words, the claim is that the terms of the sequence satisfy the
equation an = 2·5n −1.
• Prove that this is true.
Mathematical Induction II
• Proving a Property of a Sequence
• Solution a.
• a1 = 2.
• a2 = 5a2−1 = 5a1 = 5·2 = 10
• a3 = 5a3−1 = 5a2 = 5·10 = 50
• a4 = 5a4−1 = 5a3 = 5·50 = 250.
• b. To use mathematical induction to show that every term of the sequence
satisfies the equation, begin by showing that the first term of the
sequence satisfies the equation.
• Then suppose that an arbitrarily chosen term ak satisfies the equation and
prove that the next term ak +1 also satisfies the equation.
Mathematical Induction II
• Proof:
• Let a1, a2, a3, . . . be the sequence defined by specifying that a 1 = 2 and ak =
5ak−1 for all integers k ≥ 2, and let the property P(n) be the equation
• an = 2·5n−1. ← P(n)
• Use mathematical induction to prove that for all integers n ≥ 1, P(n) is true.
• Show that P(1) is true:
• a1 = 2·51−1. ← P(1)
• But the left-hand side of P(1) is
• a1 = 2 by definition of a1, a2, a3, . . .,
• and the right-hand side of P(1) is
• 2·51−1 = 2·50 = 2·1 = 2.
• Thus the two sides of P(1) are equal to the same quantity, and hence P(1) is true.
Mathematical Induction II
• Show that for all integers k ≥ 1, if P(k) is true then P(k + 1) is also true:
• Suppose that P(k) is true for a particular but arbitrarily chosen integer k≥1.
• Let k be any integer with k ≥ 0, and suppose that
• ak = 2·5k−1. ← P(k) inductive hypothesis
• Show that ak+1 = 2·5(k+1)−1 or ak+1 = 2·5k
• But the LHS of P(k + 1) is
• ak+1 = 5a(k+1)−1 by definition of a1, a2, a3, . . .
• = 5ak since (k + 1) − 1 = k
• = 5· (2·5k−1) by inductive hypothesis
• = 2· (5·5k−1) by regrouping
• = 2·5k by the laws of exponents
• = RHS
Strong Mathematical Induction and the
Well-Ordering Principle for the Integers
Principle of Strong Mathematical Induction
Let P(n) be a property that is defined for integers n, and let a
and b be fixed integers with a ≤ b. Suppose the following two
statements are true:
1. P(a), P(a + 1), . . . , and P(b) are all true. (basis step)
2. For any integer k ≥ b, if P(i) is true for all integers i from a
through k, then P(k + 1) is true. (inductive step)
Then the statement
for all integers n ≥ a, P(n) is true.
Strong Mathematical Induction and the
Well-Ordering Principle for the Integers
• The supposition that P(i) is true for all integers i from a
through k is called the inductive hypothesis.
• Another way to state the inductive hypothesis is to say
that P(a), P(a + 1), . . . , P(k) are all true.
Applying Strong Mathematical Induction

• Divisibility by a Prime:
•Proof (by strong mathematical induction):
•Let the property P(n) be the sentence
• n is divisible by a prime number. ← P(n)
•Show that P(2) is true:
• 2 is divisible by a prime number. ← P(2)
•But this is true because 2 is divisible by 2 & 2 is a prime no.
•Show that for all integers k ≥ 2, if P(i) is true for all integers
i from 2 through k, then P(k + 1) is also true:
Proving a Property of a Sequence with
Strong Induction
•Define a sequence s0, s1, s2, . . . as follows:
• s0 = 0, s1 = 4, sk = 6sk−1 − 5sk−2 for all integers k ≥ 2.
a. Find the first four terms of this sequence.
b. It is claimed that for each integer n ≥ 0, the nth term of
the sequence has the same value as that given by the
formula 5n − 1. In other words, the claim is that all the
terms of the sequence satisfy the equation sn = 5n − 1.
Prove that this is true.
Proving a Property of a Sequence with
Strong Induction
•Solution a.
•s0 = 0,
•s1 = 4,
•s2 = 6s1 − 5s0 = 6·4 − 5·0 = 24,
•s3 = 6s2 − 5s1 = 6·24 − 5·4 = 144 − 20 = 124
Proving a Property of a Sequence with
Strong Induction
•Solution b.
•To use strong mathematical induction to show that every term of
the sequence satisfies the equation, the basis step must show that
the first two terms satisfy it.
•This is necessary because, according to the definition of the
sequence, computing values of later terms requires knowing the
values of the two previous terms.
•So if the basis step only shows that the first term satisfies the
equation, it would not be possible to use the inductive step to
deduce that the second term satisfies the equation.
Proving a Property of a Sequence with
Strong Induction
•In the inductive step you suppose that for an arbitrarily
chosen integer k ≥ 1, all the terms of the sequence from s0
through sk satisfy the given equation and you then deduce
that sk+1 must also satisfy the equation.
Proving a Property of a Sequence with
Strong Induction
•sn = 5n − 1 ← P(n)
•s0 = 50 − 1 and s1 = 51 − 1. ← P(0) and P(1)
•Show that for all integers k ≥ 1, if P(i) is true for all integers i
from 0 through k, then P(k + 1) is also true:
•Let k be any integer with k ≥ 1 and suppose that
•si = 5i − 1 for all integers i with 0 ≤ i ≤ k. ←inductive hypothesis
•show that sk+1 = 5k+1 − 1. ← P(k + 1)
Proving a Property of a Sequence with
Strong Induction
•But since k ≥ 1, we have that k + 1 ≥ 2, and so
•sk+1 = 6sk − 5sk−1 by definition of s0, s1, s2, . . .
• = 6(5k − 1) − 5(5k−1 − 1) by definition hypothesis
• = 6·5k − 6 − 5k + 5 by multiplying out & applying a law of exponents
• = (6 − 1)5k − 1 by factoring out 6 and arithmetic
• = 5·5k − 1 by arithmetic
• = 5k+1 − 1 by applying a law of exponents,
•conclude that the given statement is true
The Well-Ordering Principle for the Integers
• Well-Ordering Principle for the Integers
• Let S be a set of integers containing one or more integers all of which are
greater than some fixed integer. Then S has a least element.
• Finding Least Elements
• In each case, if the set has a least element, state what it is. If not,
explain why the well ordering principle is not violated.
a. The set of all positive real numbers.
b. The set of all nonnegative integers n such that n2 < n.
c. The set of all nonnegative integers of the form 46 − 7k, where k is
an integer.
The Well-Ordering Principle for the Integers
• Solution:
a. The set of all positive real numbers.
• There is no least positive real number.
• For if x is any positive real number, then x/2 is a positive real number
that is less than x.
• No violation of the well-ordering principle occurs because the well-
ordering principle refers only to sets of integers, and this set is not a
set of integers.
The Well-Ordering Principle for the Integers
• Solution:
b. The set of all nonnegative integers n such that n2 < n.
• There is no least nonnegative integer n such that n2 < n because there
is no nonnegative integer that satisfies this inequality.
• The well-ordering principle is not violated because the well-ordering
principle refers only to sets that contain at least one element.
The Well-Ordering Principle for the Integers
• Solution:
c. The set of all nonnegative integers of the form 46 − 7k, where k is an
integer.
• The following table shows values of 46 − 7k for various values of k.

K 0 1 2 … 7 … -1 -2 -3 …
46-7k 46 39 32 … -3 … 53 60 67 …
• 46 − 7k < 0 for k ≥ 7 and that 46 − 7k ≥ 46 for k ≤ 0.
• Therefore, from the other values in the table it is clear that 4 is the least
nonnegative integer of the form 46 − 7k. This corresponds to k = 6.
Application: Correctness of Algorithms
• Algorithm Pre-Conditions and Post-Conditions
• Here are pre- and post-conditions for some typical
algorithms.
• a. Algorithm to compute a product of nonnegative integers
• Pre-condition: The input variables m and n are nonnegative
integers.
• Post-condition: The output variable p equals mn.
Application: Correctness of Algorithms
• Algorithm Pre-Conditions and Post-Conditions
• b. Algorithm to find quotient and remainder of the division
of one positive integer by another
• Pre-condition: The input variables a and b are positive
integers.
• Post-condition: The output variables q and r are integers
such that a = bq + r and 0 ≤ r < b.
Application: Correctness of Algorithms
• Algorithm Pre-Conditions and Post-Conditions
• c. Algorithm to sort a one-dimensional array of real numbers
• Pre-condition: The input variable A[1], A[2], . . . , A[n] is a
one-dimensional array of real numbers.
• Post-condition: The output variable B[1], B[2], . . . , B[n] is a
one-dimensional array of real numbers with same elements
as A[1], A[2], . . . , A[n] but with the property that B[i] ≤ B[ j ]
whenever i ≤ j.
Application: Correctness of Algorithms
• A proof of algorithm correctness consists of showing that if
the pre-condition for the algorithm is true for a collection of
values for the input variables and if the statements of the
algorithms are executed, then the post-condition is also true.
• The divide-and-conquer principle has been useful in many
aspects of computer programming, and proving algorithm
correctness is no exception.
Application: Correctness of Algorithms
• The divide-and-conquer principle has been useful in many aspects of computer
programming, and proving algorithm correctness is no exception.
• The steps of an algorithm are divided into sections with assertions about the current state
of algorithm variables inserted at strategically chosen points:
• [Assertion 1: pre-condition for the algorithm]
• {Algorithm statements}
• [Assertion 2]
• {Algorithm statements}
• ...
• [Assertion k − 1]
• {Algorithm statements}
• [Assertion k: post-condition for the algorithm]
Application: Correctness of Algorithms
• Successive pairs of assertions are then treated as pre- and post-
conditions for the algorithm statements between them.
• For each i = 1, 2, . . . , k − 1, one proves that if Assertion i is true
and all the algorithm statements between Assertion i and
Assertion (i + 1) are executed, then Assertion (i + 1) is true.
• Once all these individual proofs have been completed, one knows
that Assertion k is true.
• And since Assertion 1 is the same as the pre-condition for the
algorithm and Assertion k is the same as the post-condition for
the algorithm, one concludes that the entire algorithm is correct
with respect to its pre- and post-conditions.
Application: Correctness of Algorithms
• Loop Invariants:
• Definition
• A loop is defined as correct with respect to its pre- and
post-conditions if, and only if, whenever the algorithm
variables satisfy the pre-condition for the loop and the
loop terminates after a finite number of steps, the
algorithm variables satisfy the post-condition for the
loop.
Application: Correctness of Algorithms
• Theorem 5.5.1 Loop Invariant Theorem
• Let a while loop with guard G be given, together with pre- and
post-conditions that are predicates in the algorithm variables.
Also let a predicate I (n), called the loop invariant, be given. If
the following four properties are true, then the loop is correct
with respect to its pre- and post-conditions.
• I. Basis Property: The pre-condition for the loop implies that I (0)
is true before the first iteration of the loop.
Application: Correctness of Algorithms
• II. Inductive Property: For all integers k ≥ 0, if the guard G and
the loop invariant I (k) are both true before an iteration of the
loop, then I (k + 1) is true after iteration of the loop.
• III. Eventual Falsity of Guard: After a finite number of
iterations of the loop, the guard G becomes false.
• IV. Correctness of the Post-Condition: If N is the least number
of iterations after which G is false and I (N) is true, then the
values of the algorithm variables will be as specified in the
post-condition of the loop.
Application: Correctness of Algorithms
• Correctness of a Loop to Compute a Product:
• The following loop is designed to compute the product mx for a nonnegative
integer m and a real number x, without using a built-in multiplication
operation. Prior to the loop, variables i and product have been introduced and
given initial values i = 0 and product = 0.
• [Pre-condition: m is a nonnegative integer,
• x is a real number, i ≠ 0, and product = 0.]
while (i ≠ m)
1. product := product + x
2. i := i + 1
end while
• [Post-condition: product = mx]
Application: Correctness of Algorithms
• Let the loop invariant be
• I (n): i = n and product = nx
• The guard condition G of the while loop is
• G: i ≠ m
• Use the loop invariant theorem to prove that the while loop is correct
with respect to the given pre- and post-conditions.
Application: Correctness of Algorithms
• Solution
• I. Basis Property: [I (0) is true before the first iteration of the loop.]
• I (0) is “i = 0 and product = 0· x”, which is true before the first iteration
of the loop because 0· x = 0.
Application: Correctness of Algorithms
• Solution
• II. Inductive Property: [If G ∧ I (k) is true before a loop iteration (where
k ≥ 0), then I (k + 1) is true after the loop iteration.]
• Suppose k is a nonnegative integer such that G ∧ I (k) is true before an
iteration of the loop.
• Then as execution reaches the top of the loop, I ≠ m, product = kx, and
i = k.
• Since i ≠ m, the guard is passed and statement 1 is executed. Before
execution of statement 1,
• productold= kx.
Application: Correctness of Algorithms
• Solution
• Thus execution of statement 1 has the following effect:
• productnew= productold+ x = kx + x = (k + 1)x.
• Similarly, before statement 2 is executed,
• iold = k,
• so after execution of statement 2,
• inew = iold + 1 = k + 1.
• Hence after the loop iteration, the statement I (k + 1) , namely, (i = k +
1 and product = (k + 1)x), is true. This is what we needed to show.
Application: Correctness of Algorithms
• Solution
• IV. Correctness of the Post-Condition: [If N is the least number of
iterations after which G is false and I (N) is true, then the value of the
algorithm variables will be as specified in the post-condition of the
loop.]
• According to the post-condition, the value of product after execution of
the loop should be mx.
• But if G becomes false after N iterations, i = m. And if I (N) is true, i = N
and product = Nx. Since both conditions (G false and I (N) true) are
satisfied, m = i = N and product = mx as required.
Application: Correctness of Algorithms
• Solution
• III. Eventual Falsity of Guard: [After a finite number of iterations of the
loop, G becomes false.]
• The guard G is the condition i ≠ m, and m is a nonnegative integer.
• By I and II, it is known that
• for all integers n ≥ 0, if the loop is iterated
• n times, then i = n and product = nx.
• So after m iterations of the loop, i = m. Thus G becomes false after m
iterations of the loop.
Defining Sequences Recursively
• Definition
• A recurrence relation for a sequence a0, a1, a2, . . . is a formula that
relates each term ak to certain of its predecessors ak−1, ak−2, . . . , ak−i ,
where i is an integer with k − i ≥ 0.
• The initial conditions for such a recurrence relation specify the
values of a0, a1, a2, . . . , ai−1, if i is a fixed integer, or a0, a1, a2, .. . , am,
where m is an integer with m ≥ 0, if i depends on k.
Computing Terms of a Recursively Defined
Sequence
• Define a sequence c0, c1, c2, . . . recursively as follows: For all integers k
≥ 2,
1) ck = ck−1 + kck−2 + 1 recurrence relation
2) c0 = 1 and c1 = 2 initial conditions.
• Find c2, c3, and c4.
• Solution
• c2 = c1 + 2c0 + 1 by substituting k = 2 into (1)
• = 2 + 2·1 + 1 since c1 = 2 and c0 = 1 by (2)
• =5
Computing Terms of a Recursively Defined
Sequence
• (3) ∴ c2 = 5
• c3 = c2 + 3c1 + 1 by substituting k = 3 into (1)
• = 5 + 3·2 + 1 since c2 = 5 by (3) and c1 = 2 by (2)

• (4) ∴ c3 = 12
• c4 = c3 + 4c2 + 1 by substituting k = 4 into (1)
• = 12 + 4·5 + 1 since c3 = 12 by (4) and c2 = 5 by (3)

• (5) ∴ c4 = 33
• A given recurrence relation may be expressed in several different
ways.
Writing a Recurrence Relation in More Than
One Way
• Let s0, s1, s2, . . . be a sequence that satisfies the following recurrence
relation:
• for all integers k ≥ 1, sk = 3sk−1 − 1.
• Explain why the following statement is true:
• for all integers k ≥ 0, sk+1 = 3sk − 1.
• Solution In informal language, the recurrence relation says that any
term of the sequence equals 3 times the previous term minus 1.
• Now for any integer k ≥ 0, the term previous to sk+1 is sk .
• Thus for any integer k ≥ 0, sk+1 = 3sk − 1.
Sequences That Satisfy the Same Recurrence
Relation
• Let a1, a2, a3, . . . and b1, b2, b3, . . . satisfy the recurrence relation that
the kth term equals 3 times the (k − 1)st term for all integers k ≥ 2:
• (1) ak = 3ak−1 and bk = 3bk−1
• But suppose that the initial conditions for the sequences are different:
• (2) a1 = 2 and b1 = 1.
• Find (a) a2, a3, a4 and (b) b2, b3, b4.
Sequences That Satisfy the Same Recurrence
Relation
• Solution
• a. a2 = 3a1 = 3·2 = 6
• a3 = 3a2 = 3·6 = 18
• a4 = 3a3 = 3·18 = 54
• b. b2 = 3b1 = 3·1 = 3
• b3 = 3b2 = 3·3 = 9
• b4 = 3b3 = 3·9 = 27
• Thus a1, a2, a3, . . . begins 2, 6, 18, 54, . . . and
• b1, b2, b3, . . . begins 1, 3, 9, 27, . . . .
Showing That a Sequence Given by an Explicit
Formula Satisfies a Certain Recurrence Relation
• The sequence of Catalan numbers, named after the Belgian
mathematician Eugène Catalan (1814–1894), arises in a remarkable
variety of different contexts in discrete mathematics.
• It can be defined as follows: For e
• ach integer n ≥ 1,
Showing That a Sequence Given by an Explicit
Formula Satisfies a Certain Recurrence Relation
Showing That a Sequence Given by an Explicit
Formula Satisfies a Certain Recurrence Relation
Showing That a Sequence Given by an Explicit
Formula Satisfies a Certain Recurrence Relation
Examples of Recursively Defined Sequences
• The Tower of Hanoi
• The Fibonacci Numbers
• Compound Interest
• Recursive Definitions of Sum and Product
Recursive Algorithms
• A recursive function is a function that is defined in terms of itself.

• Similarly, an algorithm is said to be recursive if the same algorithm is


invoked in the body.

• An algorithm that calls itself is direct recursive.

• Algorithm A is said to be indirect recursive if it calls another algorithm


which in turn calls A.

• These recursive mechanisms are extremely powerful, but even more


importantly, many times they can express an otherwise complex
process very clearly.
Recursive Algorithms
Void recurse()
{
... .. ...
recurse();
... .. ...
}

int main()
{
... .. ...
recurse();
... .. ...
}
Recursive Algorithms
void count_to_ten ( int count )
{
/* we only keep counting if we have a value less than ten
if ( count < 10 )
{
count_to_ten( count + 1 );
}
}
int main()
{
count_to_ten ( 0 );
}
Example: Sum of Natural Numbers using Recursion
#include <stdio.h> int sum(int n)
int sum(int n); {
if (n != 0)
int main() { // sum() function calls itself
int number, result; return n + sum(n-1);
else
printf("Enter a positive integer: "); return n;
scanf("%d", &number); } Return 3 + sum (2)
Return 2+ sum (1)
result = sum(number); Return 1+ sum (0)
Return 0
Output
printf("sum = %d", result); Enter a positive integer: 3
return 0; } sum = 6
Tower of Hanoi
• There are three towers, 64 gold disks, with decreasing
sizes, placed on the first tower (bottom to top)
• You need to move all of the disks from the first tower
to the second tower
• Larger disks can not be placed on top of smaller disks
• The third tower can be used to temporarily hold disks
• To generalize the problem, we will consider this
problem as “N-disk” problem
Recursive Solution

Tower A Tower B Tower C


Recursive Solution

Tower A Tower B Tower C


Recursive Solution

Tower A Tower B Tower C


Recursive Solution

Tower A Tower B Tower C


Tower of Hanoi

Tower A Tower B Tower C


Tower of Hanoi

Tower A Tower B Tower C


Tower of Hanoi

Tower A Tower B Tower C


Tower of Hanoi

Tower A Tower B Tower C


Tower of Hanoi

Tower A Tower B Tower C


Tower of Hanoi

Tower A Tower B Tower C


Tower of Hanoi

Tower A Tower B Tower C


Tower of Hanoi

Tower A Tower B Tower C


Tower of Hanoi
Algorithm TowersOfHanoi(n, x, y, z)
// Move the top n disks from tower x to tower y
{
if (n >= 1) then
{
TowersOfHanoi(n-1, x, z, y);
write ("move top disk from tower ", x, "to top of
tower", y);
TowersOfHanoi(n-1, z, y, x);
}
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy