Download presentation
Presentation is loading. Please wait.
1
SECTION 5.1 Sequences
2
Sequences Problem: count number of ancestors
one has 2 parents, 4 grandparents, 8 great- grandparents, …, written in a row as 2, 4, 8, 16, 32, 64, 128,… To look for pattern of the numbers, For a general value of k, let Ak be the number of ancestors in k-th generation back. We have :
3
Sequences In a sequence a1, a2, a3,…, ak,…
each individual element ak (“a sub k”) is called a term. k in ak is called a subscript or index An explicit formula or closed formula for a sequence is a rule that shows how the values of ak depend on k.
4
Finding Terms of Sequences Given by Explicit Formulas
Define sequences a1, a2, a3,… and b2, b3, b4,… by the following explicit formulas: Compute the first five terms of both sequences.
5
Summation Notation
6
Summation Notation What is the total number of ancestors for the past six generations? The answer is It is convenient to use a shorthand notation to write such sums.
7
Summation Notation introduced in 1772 by French mathematician Joseph Louis Lagrange
8
Summation Notation Oftentimes, the terms of a summation are expressed using an explicit formula. For instance, Write the following summation in expanded form:
9
from Expanded Form to Summation Notation
Express the following using summation notation:
10
Summation Notation A more mathematically precise definition of summation, called a recursive definition, is the following: If m is any integer, then
11
Separating Off a Final Term and Adding On a Final Term
When solving problems, it is often useful to rewrite a summation using the recursive form of the definition, either by separating off the final term of a summation or by adding a final term to a summation. a. Rewrite by separating off the final term. b. Write as a single summation.
12
A Telescoping Sum Some sums can be transformed into telescoping sums, which then can be rewritten as a simple expression. For instance, observe that Use this identity to find a simple expression for
13
Product Notation
14
Product Notation The notation for the product of a sequence of numbers is analogous to the notation for their sum. The Greek capital letter pi, , denotes a product.
15
Product Notation A recursive definition for the product notation is the following: If m is any integer, then
16
Example 11 – Computing Products
Compute the following products: a. b.
17
Properties of Summations and Products
18
Using Properties of Summation and Product
Let ak = k + 1 and bk = k − 1 for all integers k. Write each of the following expressions as a single summation or product: a b.
19
Change of Variable
20
Change of Variable Observe that and also that Hence
k,i are symbols used to represent index of a summation. They can be replaced by any other symbol as long as the replacement is made in each location where the symbol occurs.
21
Transforming a Sum by a Change of Variable
Transform summation by making specified change of variable. summation: change of variable: 1. calculate lower and upper limits of new summation: so j starts from 1 go up to 7. 2. find formula for new summation: replace each occurrence of k by an expression in j : 3. Finally, put the steps together to obtain
22
Change variables a. Transform the following summation by making the specified change of variable. summation: change of variable: b. Transform the summation obtained in part (a) by changing all j’s to k’s.
23
Defining Sequences Recursively
SECTION 5.6 Defining Sequences Recursively Copyright © Cengage Learning. All rights reserved.
24
Defining Sequences Recursively
Sometimes a sequence is defined using recursion. an equation, called a recurrence relation, that defines each later term by reference to earlier terms together with one or more initial values for the sequence.
25
Computing Terms of a Recursively Defined Sequence
Define a sequence c0, c1, c2, recursively as follows: For all integers k ≥ 2, Find c2, c3, and c4.
26
b. Show that this sequence satisfies recurrence
Example 4 – Showing That a Sequence Given by an Explicit Formula Satisfies a Certain Recurrence Relation The sequence of Catalan numbers (named after Belgian mathematician Eugène Catalan,1814–1894), arises in different contexts in discrete mathematics. For each integer n ≥ 1, a. Find C1,C2, and C3. b. Show that this sequence satisfies recurrence relation for all integers k ≥ 2
27
Examples of Recursively Defined Sequences
28
Examples of Recursively Defined Sequences
Recursion is one of the central ideas of computer science. To solve a problem recursively means to find a way to break it down into smaller subproblems each having same form as original problem when the process is repeated many times, the last of the subproblems are small and easy to solve the solutions of the subproblems can be woven together to form a solution to the original problem.
29
Example:The Tower of Hanoi
invented in 1883 by a French mathematician, Édouard Lucas 3 poles 8 disks of wood with holes in their centers, piled in order of decreasing size on one pole i How to move all the disks one by one from pole A to pole C, never placing a larger disk on top of a smaller one? how many moves would be required to win the prize?
30
Think Recursively! Suppose that you have found most efficient way possible to transfer a tower of k – 1 disks from one pole to another, obeying given restriction. What is the most efficient way to transfer a tower of k disks from one pole to another?
31
Solution cont’d Step 1: Transfer top k – 1 disks from A to B. (If k > 2, execution of this step will require a number of moves of individual disks among the three poles.) Art of thinking recursively: not to get caught up in imagining the details of how those moves will occur. Step 2: Move disk from A to C. Step 3: Transfer k – 1 disks from pole B to pole C. (Again, if k > 2, execution of this step will require more than one move.)
32
Is this most efficient way?
cont’d To move bottom disk of a stack of k disks from one pole to another, you must first transfer top k – 1 disks to a third pole to get them out of the way. Transferring the stack of k disks from pole A to pole C requires at least two transfers of the top k – 1 disks: one to transfer them off the bottom disk to free the bottom disk so that it can be moved another to transfer them back on top of bottom disk after the bottom disk has been moved to pole C.
33
How many moves? cont’d It follows that For each integer n ≥ 1, let
34
Solution mn are independent of
cont’d mn are independent of the labeling of the poles; it takes the same minimum number of moves to transfer n disks from pole A to pole C as to transfer n disks from pole A to pole B, for example. independent of number of larger disks that may lie below top n, provided these remain stationary while the top n are moved.
35
How many moves? cont’d It follows that
36
Solution cont’d Because just one move is needed to move one disk from one pole to another, Hence the complete recursive specification of the sequence m1, m2, m3, is as follows: For all integers k ≥ 2,
37
Solution Here is a computation of the next five terms of the sequence:
cont’d Here is a computation of the next five terms of the sequence: Going back to the legend, suppose the priests work rapidly and move one disk every second. Then the time from the beginning of creation to the end of the world would be m64 seconds.
38
Example 5 – Solution We can compute m64 on a calculator.
cont’d We can compute m64 on a calculator. The approximate result is which is obtained by the estimate of seconds in a year (figuring days in a year to take leap years into account). Surprisingly, this figure is close to some scientific estimates of the life of the universe!
39
Recursive Definitions of Sum and Product
40
Recursive Definitions of Sum and Product
Addition and multiplication are called binary operations because only two numbers can be added or multiplied at a time. Careful definitions of sums and products of more than two numbers use recursion.
41
Recursive Definitions of Sum and Product
The effect of these definitions is to specify an order in which sums and products of more than two numbers are computed. For example, The recursive definitions are used with mathematical induction to establish various properties of general finite sums and products.
42
Example 9 – A Sum of Sums Prove that for any positive integer n, if a1, a2, , an and b1, b2, , bn are real numbers, then Solution: The proof is by mathematical induction. Let the property P(n) be the equation
43
Example 9 – Solution cont’d We must show that P(n) is true for all integers n ≥ 0.We do this by mathematical induction on n. Show that P(1) is true: To establish P(1), we must show that But Hence P(1) is true.
44
Example 9 – Solution cont’d Show that for all integers k ≥ 1, if P(k) is true then P(k + 1) is also true: Suppose a1, a2, , ak, ak + 1 and b1, b2, , bk, bk + 1 are real numbers and that for some k ≥ 1 We must show that [We will show that the left-hand side of this equation equals the right-hand side.]
45
Example 9 – Solution cont’d But the left-hand side of the equation is
46
Example 9 – Solution cont’d which equals the right-hand side of the equation. [This is what was to be shown.]
47
Solving Recurrence Relations by Iteration
SECTION 5.7 Solving Recurrence Relations by Iteration Copyright © Cengage Learning. All rights reserved.
48
Solving Recurrence Relations by Iteration
Suppose you have a sequence that satisfies a certain recurrence relation and initial conditions. It is often helpful to know an explicit formula for the sequence, especially if you need to compute terms with very large subscripts or if you need to examine general properties of the sequence. Such an explicit formula is called a solution to the recurrence relation. In this section, we discuss methods for solving recurrence relations.
49
The Method of Iteration
The most basic method for finding an explicit formula for a recursively defined sequence is iteration. Iteration works as follows: Given a sequence a0, a1, a2, defined by a recurrence relation and initial conditions, you start from the initial conditions and calculate successive terms of the sequence until you see a pattern developing. At that point you guess an explicit formula.
50
Example 1 – Finding an Explicit Formula
Let a0, a1, a2, be the sequence defined recursively as follows: For all integers k ≥ 1, Use iteration to guess an explicit formula for the sequence. Solution: We know that to say means
51
Example 1 – Solution In particular, and so forth.
cont’d In particular, and so forth. Now use the initial condition to begin a process of successive substitutions into these equations, not just of numbers but of numerical expressions.
52
Example 1 – Solution cont’d The reason for using numerical expressions rather than numbers is that in these problems you are seeking a numerical pattern that underlies a general formula. The secret of success is to leave most of the arithmetic undone. However, you do need to eliminate parentheses as you go from one step to the next. Otherwise, you will soon end up with a bewilderingly large nest of parentheses.
53
Example 1 – Solution cont’d Also, it is nearly always helpful to use shorthand notations for regrouping additions, subtractions, and multiplications of numbers that repeat. Thus, for instance, you would write and Notice that you don’t lose any information about the number patterns when you use these shorthand notations.
54
Example 1 – Solution cont’d Here’s how the process works for the given sequence:
55
Example 1 – Solution cont’d Since it appears helpful to use the shorthand k ● 2 in place of · · · + 2 (k times), we do so, starting again from a0.
56
Example 1 – Solution Guess:
cont’d Guess: The answer obtained for this problem is just a guess. To be sure of the correctness of this guess, you will need to check it by mathematical induction.
57
The Method of Iteration
A sequence like the one in Example 1, in which each term equals the previous term plus a fixed constant, is called an arithmetic sequence.
58
Example 2 – An Arithmetic Sequence
Under the force of gravity, an object falling in a vacuum falls about 9.8 meters per second (m/sec) faster each second than it fell the second before. Thus, neglecting air resistance, a skydiver’s speed upon leaving an airplane is approximately 9.8m/sec one second after departure, = 19.6m/sec two seconds after departure, and so forth. If air resistance is neglected, how fast would the skydiver be falling 60 seconds after leaving the airplane?
59
Example 2 – Solution Let sn be the skydiver’s speed in m/sec n seconds after exiting the airplane if there were no air resistance. Thus s0 is the initial speed, and since the diver would travel 9.8m/sec faster each second than the second before, It follows that s0, s1, s2, is an arithmetic sequence with a fixed constant of 9.8, and thus
60
Example 2 – Solution cont’d Hence sixty seconds after exiting and neglecting air resistance, the skydiver would travel at a speed of Note that 588 m/sec is over half a kilometer per second or over a third of a mile per second, which is very fast for a human being to travel. Happily for the skydiver, taking air resistance into account cuts the speed considerably.
61
The Method of Iteration
Let r be a fixed nonzero constant, and suppose a sequence a0, a1, a2, is defined recursively as follows: Use iteration to guess an explicit formula for this sequence.
62
The Method of Iteration
An important property of a geometric sequence with constant multiplier greater than 1 is that its terms increase very rapidly in size as the subscripts get larger and larger. For instance, the first ten terms of a geometric sequence with a constant multiplier of 10 are Thus, by its tenth term, the sequence already has the value 109 = 1,000,000,000 = 1 billion.
63
The Method of Iteration
The following box indicates some quantities that are approximately equal to certain powers of 10.
64
Using Formulas to Simplify Solutions Obtained by Iteration
65
Using Formulas to Simplify Solutions Obtained by Iteration
Explicit formulas obtained by iteration can often be simplified by using formulas such as those developed earlier. For instance, according to the formula for the sum of a geometric sequence with initial term 1 (Theorem 5.2.3), for each real number r except r = 1,
66
Using Formulas to Simplify Solutions Obtained by Iteration
And according to the formula for the sum of the first n integers (Theorem 5.2.2),
67
Example 5 – An Explicit Formula for the Tower of Hanoi Sequence
The Tower of Hanoi sequence m1, m2, m3, satisfies the recurrence relation and has the initial condition Use iteration to guess an explicit formula for this sequence, to simplify the answer.
68
Example 5 – Solution By iteration
69
Example 5 – Solution cont’d These calculations show that each term up to m5 is a sum of successive powers of 2, starting with 20 = 1 and going up to 2k, where k is 1 less than the subscript of the term. The pattern would seem to continue to higher terms because each term is obtained from the preceding one by multiplying by 2 and adding 1; multiplying by 2 raises the exponent of each component of the sum by 1, and adding 1 adds back the 1 that was lost when the previous 1 was multiplied by 2. For instance, for n = 6,
70
Example 5 – Solution Thus it seems that, in general,
cont’d Thus it seems that, in general, By the formula for the sum of a geometric sequence (Theorem 5.2.3),
71
Example 5 – Solution cont’d Hence the explicit formula seems to be
72
Checking the Correctness of a Formula by Mathematical Induction
Come back to this later….
73
Checking the Correctness of a Formula by Mathematical Induction
It is all too easy to make a mistake and come up with the wrong formula. That is why it is important to confirm your calculations by checking the correctness of your formula. The most common way to do this is to use mathematical induction.
74
Example 7 – Using Mathematical Induction to Verify the Correctness of a Solution to a Recurrence Relation In 1883 a French mathematician, Édouard Lucas, invented a puzzle that he called The Tower of Hanoi (La Tour D’Hanoï). The puzzle consisted of eight disks of wood with holes in their centers, which were piled in order of decreasing size on one pole in a row of three. Those who played the game were supposed to move all the disks one by one from one pole to another, never placing a larger disk on top of a smaller one.
75
Example 7 – Using Mathematical Induction to Verify the Correctness of a Solution to a Recurrence Relation cont’d The puzzle offered a prize of ten thousand francs (about $34,000 US today) to anyone who could move a tower of 64 disks by hand while following the rules of the game. (See Figure 5.6.2) Assuming that you transferred the disks as efficiently as possible, how many moves would be required to win the prize? Figure 5.6.2
76
The solution to this is as follows:
Example 7 – Using Mathematical Induction to Verify the Correctness of a Solution to a Recurrence Relation cont’d The solution to this is as follows: Let m be the minimum number of moves needed to transfer a tower of k disks from one pole to another. Then, Use mathematical induction to show that this formula is correct.
77
Example 7 – Solution What does it mean to show the correctness of a formula for a recursively defined sequence? Given a sequence of numbers that satisfies a certain recurrence relation and initial condition, your job is to show that each term of the sequence satisfies the proposed explicit formula. In this case, you need to prove the following statement:
78
Example 7 – Solution Proof of Correctness:
cont’d Proof of Correctness: Let m1, m2, m3, be the sequence defined by specifying that m1 = 1 and mk = 2mk for all integers k ≥ 2, and let the property P(n) be the equation We will use mathematical induction to prove that for all integers n ≥ 1, P(n) is true. Show that P(1) is true: To establish P(1), we must show that
79
Example 7 – Solution But the left-hand side of P(1) is
cont’d But the left-hand side of P(1) is and the right-hand side of P(1) is Thus the two sides of P(1) equal the same quantity, and hence P(1) is true.
80
Example 7 – Solution cont’d 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. That is:] Suppose that k is any integer with k ≥ 1 such that [We must show that P(k + 1) is true. That is:] We must show that
81
Example 7 – Solution But the left-hand side of P(k + 1) is
cont’d But the left-hand side of P(k + 1) is which equals the right-hand side of P(k + 1). [Since the basis and inductive steps have been proved, it follows by mathematical induction that the given formula holds for all integers n ≥ 1.]
82
Discovering That an Explicit Formula Is Incorrect
83
Discovering That an Explicit Formula Is Incorrect
The next example shows how the process of trying to verify a formula by mathematical induction may reveal a mistake.
84
Let c0, c1, c2, . . . be the sequence defined as follows:
Example 8 – Using Verification by Mathematical Induction to Find a Mistake Let c0, c1, c2, be the sequence defined as follows: Suppose your calculations suggest that c0, c1, c2, satisfies the following explicit formula: Is this formula correct?
85
Example 8 – Solution Start to prove the statement by mathematical induction and see what develops. The proposed formula passes the basis step of the inductive proof with no trouble, for on the one hand, c0 = 1 by definition and on the other hand, = = 1 also. In the inductive step, you suppose and then you must show that
86
Example 8 – Solution cont’d To do this, you start with ck+1, substitute from the recurrence relation, and then use the inductive hypothesis as follows: To finish the verification, therefore, you need to show that
87
Example 8 – Solution Now this equation is equivalent to
cont’d Now this equation is equivalent to which is equivalent to But this is false since k may be any nonnegative integer. Observe that when k = 0, then k + 1 = 1, and
88
Example 8 – Solution cont’d Thus the formula gives the correct value for c1. However, when k = 1, then k + 1 = 2, and So the formula does not give the correct value for c2. Hence the sequence c0, c1, c2, does not satisfy the proposed formula.
89
Discovering That an Explicit Formula Is Incorrect
Once you have found a proposed formula to be false, you should look back at your calculations to see where you made a mistake, correct it, and try again.
90
Sequences in Computer Programming
91
Sequences in Computer Programming
An important data type in computer programming consists of finite sequences. In computer programming contexts, these are usually referred to as one-dimensional arrays. For example, consider a program that analyzes the wages paid to a sample of 50 workers. Such a program might compute the average wage and the difference between each individual wage and the average.
92
Sequences in Computer Programming
This would require that each wage be stored in memory for retrieval later in the calculation. To avoid the use of entirely separate variable names for all of the 50 wages, each is written as a term of a one- dimensional array:
93
Example 18 – Dummy Variable in a Loop
The index variable for a for-next loop is a dummy variable. For example, the following three algorithm segments all produce the same output:
94
Sequences in Computer Programming
The recursive definitions for summation, product, and factorial lead naturally to computational algorithms. For instance, here are two sets of pseudocode to find the sum of a[1], a[2], …, a[n]. The one on the left exactly mimics the recursive definition by initializing the sum to equal a[1]; the one on the right initializes the sum to equal 0.
95
Sequences in Computer Programming
In both cases the output is
96
Application: Algorithm to Convert
from Base 10 to Base 2 Using Repeated Division by 2
97
Application: Algorithm to Convert from Base 10 to Base 2 Using Repeated Division by 2
A systematic algorithm to convert any nonnegative integer to binary notation uses repeated division by 2. Suppose a is a nonnegative integer. Divide a by 2 using the quotient-remainder theorem to obtain a quotient q[0] and a remainder r [0]. If the quotient is nonzero, divide by 2 again to obtain a quotient q[1] and a remainder r [1]. Continue this process until a quotient of 0 is obtained. At each stage, the remainder must be less than the divisor, which is 2. Thus each remainder is either 0 or 1.
98
Application: Algorithm to Convert from Base 10 to Base 2 Using Repeated Division by 2
The process is illustrated below for a = 38. (Read the divisions from the bottom up.) The results of all these divisions can be written as a sequence of equations:
99
By repeated substitution, then,
Application: Algorithm to Convert from Base 10 to Base 2 Using Repeated Division by 2 By repeated substitution, then,
100
This is true for the left-most 1 as well, because 1 = 0 ● 2 + 1. Thus
Application: Algorithm to Convert from Base 10 to Base 2 Using Repeated Division by 2 Note that each coefficient of a power of 2 on the right-hand side is one of the remainders obtained in the repeated division of 38 by 2. This is true for the left-most 1 as well, because 1 = 0 ● Thus
101
Application: Algorithm to Convert from Base 10 to Base 2 Using Repeated Division by 2
In general, if a nonnegative integer a is repeatedly divided by 2 until a quotient of zero is obtained and the remainders are found to be r [0], r [1], , r [k], then by the quotient- remainder theorem each r [i ] equals 0 or 1, and by repeated substitution from the theorem, Thus the binary representation for a can be read from equation (5.1.5):
102
Hence 2910 = (r[4] r[3] r[2] r[1] r[0])2 = 111012.
Example 19 – Converting from Decimal to Binary Notation Using Repeated Division by 2 Use repeated division by 2 to write the number 2910 in binary notation. Solution: Hence 2910 = (r[4] r[3] r[2] r[1] r[0])2 =
103
Application: Algorithm to Convert from Base 10 to Base 2 Using Repeated Division by 2
The procedure we have described for converting from base 10 to base 2 is formalized in the following algorithm: Algorithm Decimal to Binary Conversion Using Repeated Division by 2 [In this Algorithm the input is a nonnegative integer n. The aim of the algorithm is to produce a sequence of binary digits r [0], r [1], r [2], , r [k] so that the binary representation of a is That is,
104
Input: n [a nonnegative integer] Algorithm Body: q := n, i := 0
Application: Algorithm to Convert from Base 10 to Base 2 Using Repeated Division by 2 Input: n [a nonnegative integer] Algorithm Body: q := n, i := 0 [Repeatedly perform the integer division of q by 2 until q becomes 0. Store successive remainders in a one- dimensional array r [0], r [1], r [2], …. , r [k]. Even if the initial value of q equals 0, the loop should execute one time (so that r [0] is computed). Thus the guard condition for the while loop is i = 0 or q ≠ 0.]
105
[r [ i ] and q can be obtained by calling the division algorithm.]
Application: Algorithm to Convert from Base 10 to Base 2 Using Repeated Division by 2 while (i = 0 or q ≠ 0) r [ i ] := q mod 2 q := q div 2 [r [ i ] and q can be obtained by calling the division algorithm.] i := i + 1 end while
106
Output: r [0], r [1], r [2], ..., r [i − 1] [a sequence of integers]
Application: Algorithm to Convert from Base 10 to Base 2 Using Repeated Division by 2 [After execution of this step, the values of r [0], r [1], …, r [i − 1] are all 0’s and 1’s, and a = (r [i − 1] r [i − 2] … r [2] r [1]r [0])2.] Output: r [0], r [1], r [2], ..., r [i − 1] [a sequence of integers]
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.