Professional Documents
Culture Documents
SUMMATIONS
1
Sequences
Sequences represent ordered lists of elements.
Example:
Consider the sequence , where .
Therefore the terms of the sequence are
The Equation Game
What are the equations that describe the following sequences a1,
a2, a3, … ?
𝑎 𝑛= 2𝑛 − 1
𝑛
𝑎 𝑛= ( − 1 )
𝑎 𝑛=𝑛 2+1
𝑎 𝑛= 0.25 𝑛
Geometric progression
Definition:
A geometric progression is a sequence of the form
where the initial term a and the common ratio r are real numbers.
Example:
Let a = 1 and r = −1. Then:
where the initial term a and the common difference d are real
numbers.
Example:
Let a = −1 and d = 4. Then:
Example : Let {an} be a sequence that satisfies the recurrence relation for n =
1,2,3,4,…. and suppose that
a0 = 2 (initial condition). What are a1 , a2 and a3?
Solution:
a1 = a0 + 3 = 2 + 3 = 5
a2 = 5 + 3 = 8
a3 = 8 + 3 = 11
Fibonacci Sequence
Definition: The Fibonacci sequence, f0 ,f1 ,f2,…, is defined by:
O Initial Conditions: f0 = 0, f1 = 1
O Recurrence Relation:
Answer:
f2 = f1 + f0 = 1 + 0 = 1,
f3 = f2 + f1 = 1 + 1 = 2,
f4 = f3 + f2 = 2 + 1 = 3,
f5 = f4 + f3 = 3 + 2 = 5,
f6 = f5 + f4 = 5 + 3 = 8.
Solving Recurrence Relations
Finding a formula for the nth term of the sequence generated by a recurrence
relation is called solving the recurrence relation.
Such a formula is called a closed formula.
Example:
Let {an} be a sequence that satisfies the recurrence relation an = an-1 + 3 for n
= 2,3,4,…. and suppose that a1 = 2.
Method 1: Working upward, forward substitution
a2 = 2 + 3
a3 = (2 + 3) + 3 = 2 + 3 ∙ 2
a4 = (2 + 2 ∙ 3) + 3 = 2 + 3 ∙ 3
.
.
.
an = an-1 + 3 = (2 + 3 ∙ (n – 2)) + 3 = 2 + 3(n – 1)
Method 2: Working downward, backward substitution
an = an-1 + 3
= (an-2 + 3) + 3 = an-2 + 3 ∙ 2
= (an-3 + 3 )+ 3 ∙ 2 = an-3 + 3 ∙ 3
.
.
.
Solution:
The nth term will be
Where and .
Special Integer Sequences
O Given a few terms of a sequence, try to identify the sequence.
Conjecture a formula, recurrence relation, or some other rule.
O Some questions to ask?
O Are there repeated terms of the same value?
O Can you obtain a term from the previous term by adding an amount or
multiplying by an amount?
O Can you obtain a term by combining the previous terms in some way?
O Are they cycles among the terms?
O Do the terms match those of a well known sequence?
Example : Find formulae for the sequences with the
following first five terms: 1, ½, ¼, 1/8, 1/16
Solution: Note that the denominators are powers of 2.
The sequence with an = 1/2n is a possible match. This is a
geometric progression with a = 1 and r = ½.
or
The sum of the first 1000 terms of the sequence {an} with an=n2
for n = 1, 2, 3, … is
Proof:
Let
Geometric Series
If then
If then
Double Summations
Double summations arise in various contexts for example nested
loops in C or Java.
Example:
Some Useful Summation Formulae
Example: Find
Solution:
Example: Compute the following summation
Solution:
Algorithm Examples
search interval
a c d f g h j l m o p r s u v x z
center element
Algorithm Examples
search interval
a c d f g h j l m o p r s u v x z
center element
Algorithm Examples
search interval
a c d f g h j l m o p r s u v x z
center element
Algorithm Examples
search interval
a c d f g h j l m o p r s u v x z
center element
Algorithm Examples
search interval
a c d f g h j l m o p r s u v x z
center element
found !
Algorithm Examples
Oprocedure binary_search(x: integer; a1, a2, …, an:
integers)
Oi := 1 {i is left endpoint of search interval}
Oj := n {j is right endpoint of search interval}
Owhile (i < j)
Obegin
O m := (i + j)/2
O if x > am then i := m + 1
O else j := m
Oend
Oif x = ai then location := i
Oelse location := 0
O{location is the subscript of the term that equals x, or is
zero if x is not found}
Recursive algorithms
f(4)
f(3) f(2)
f(2)
f(1) f(0)
Oprocedure iterative_fibo(n: nonnegative integer)
Oif n = 0 then y := 0
Oelse
Obegin
O x := 0
O y := 1
O for i := 1 to n-1
O begin
O z := x + y
O x:=y
O y := z
O end
Oend {y is the n-th Fibonacci number}
OFor every recursive algorithm, there is an equivalent
iterative algorithm.