SlideShare a Scribd company logo
1 of 59
Download to read offline
RECURRENCES
遞迴式
Algorithms
Recursive Thinking
§ Recurrence Relations (Recurrences)
§ Closed-Form Solutions and Induction
§ Recursive Definitions
§ Proof by Induction
2023/2/22 2
Domino Effect/骨牌效應
板橋高中骨牌.mp4
2023/2/22 3
https://www.youtube.com/watch?v=GvpmkcUZj
aA&index=253&list=LL2B2lvcC9FXepheZcLQqjk
g
Recurrence Relations
A well-defined recurrence
relation needs a nonrecursive
base case that gives at least
one value of the function
explicitly.
recursive part
2023/2/22 4
Binary search (of sorted array)
https://en.wikipedia.org/wiki/Binary_search_algorithm
A tree representing binary search.
The array being searched here is
[20,30,40,50,80,90,100]
and the target value is 40.
https://www.geeksforgeeks.org/binary-search/
The array being searched here is
[2,5,8,12,16,23,38,56,72,91]
and the target value is 23.
𝑇 𝑛 = ቐ
Θ(1) 𝑖𝑓 𝑛 = 1,
𝑇
𝑛
2
+ Θ(1) 𝑖𝑓 𝑛 > 1.
▪ The recurrence describing the worst-
case running time of Binary search
▪ Example
▪ Example
2023/2/22 5
MERGE-SORT
▪ The recurrence describing the worst-case
running time of MERGE-SORT
https://ithelp.ithome.com.tw/articles/10278179
利用30 10 40 70 50 90 60 20由小到大排序。
▪ Example
2023/2/22 6
Fibonacci Numbers
A tiling with squares whose side lengths are
successive Fibonacci numbers:
1, 1, 2, 3, 5, 8, 13 and 21.
https://en.wikipedia.org/wiki/Fibonacci_number
https://betterprogramming.pub/
the-beauty-of-the-fibonacci-
sequence-c6f95674b94e
▪ Examples
2023/2/22 7
Solving Recurrence Equations
▪ Guess and proof by Induction
▪ Substitution method
▪ Recursion-tree method
▪ Change of Variables (Domain
Transformations)
▪ Characteristic Equations
▪ Extending Results for n, a
Power of a Positive Constant b,
to n in General
▪ Master method
2023/2/22 8
GUESS AND PROOF BY INDUCTION
2023/2/22 9
Example 1 for Guess and proof by Induction
▪ Consider the recurrence 𝑡𝑛 = ቊ
𝑡𝑛−1+1, for 𝑛 > 0
𝑡0 = 0
▪ Guess
▪ Induction
proof:
2023/2/22 10
Example 2 for Guess and proof by Induction
▪ Consider the recurrence 𝑡𝑛 = ൝
𝑡 Τ
𝑛
2
+1, for 𝑛 > 1, 𝑛 𝑎 𝑝𝑜𝑤𝑒𝑟 𝑜𝑓 2
𝑡1 = 1
▪ Guess ▪ Induction
proof:
2023/2/22 11
Example 3 for Guess and proof by Induction
▪ Consider the recurrence 𝑡𝑛 = ൝
7𝑡 Τ
𝑛
2
, for 𝑛 > 1, 𝑛 𝑎 𝑝𝑜𝑤𝑒𝑟 𝑜𝑓 2
𝑡1 = 1
▪ Guess ▪ Induction
proof:
2023/2/22 12
Example 4 (unfinished) for Guess and proof by Induction
▪ Consider the recurrence 𝑡𝑛 = ൝
2𝑡 Τ
𝑛
2
+𝑛−1, for 𝑛 > 1, 𝑛 𝑎 𝑝𝑜𝑤𝑒𝑟 𝑜𝑓 2
𝑡1 = 0
▪ There is no obvious candidate solution suggested by these values.
Learn more
techniques!!
Induction can only
verify that a solution
is correct!!
2023/2/22 13
SUBSTITUTION METHOD (代換法)
In the substitution method, we guess a bound and then use mathematical induction to prove our guess
correct.
2023/2/22 14
Example 1 of The substitution method
▪ Consider the recurrence 𝑡𝑛 = ቊ
𝑡𝑛−1+n, for 𝑛 > 1
𝑡1 = 1
2023/2/22 16
Example 2 of The substitution method
▪ Consider the recurrence 𝑡𝑛 = ቐ
𝑡𝑛−1+
2
𝑛
, for 𝑛 > 1
𝑡1 = 0
2023/2/22 17
RECURSION-TREE METHOD
2023/2/22 18
Height, Depth and Level of a Tree (2022/2/22 add )
2023/2/22 19
http://typeocaml.com/2014/11/26/height-depth-and-level-of-a-tree/
Height of node – The height of a node is the
number of edges on the longest downward
path between that node and a leaf.
Depth –The depth of a node is the number of
edges from the node to the tree's root node.
Level – The level of a node is defined
by 1 + the number of connections
between the node and the root.
Example 1 for recursion tree
The construction of a recursion tree for the recurrence
T (n) = 2T (n/2) + cn.
In a recursion tree, each node represents the cost of a
single subproblem somewhere in the set of recursive
function invocations.
A recursion tree is best used to generate a good guess,
which is then verified by the mathematical induction .
2023/2/22 20
Example 2 for recursion tree
The construction of a recursion tree for the recurrence
T (n) = 3T (n/4) + cn2.
2023/2/22 21
Use the substitution method to verify that our guess
was correct for example 2
Prove that T (n) = O(n2) is an upper bound for the
recurrence T (n) = 3T (n/4) + cn2.
Only induction
step for short
2023/2/22 22
Example 3 for recursion tree
The construction of a recursion tree for the recurrence
T (n) = T (n/3) + T (2n/3) + O(n).
The longest path from the root to a leaf is n→(2/3)n→(2/3)2n→· · ·→1.
Since (2/3)kn = 1 when k = log3/2 n, the height of the tree is log3/2 n.
2023/2/22 23
Use the substitution method to verify that our guess
was correct for example 2
Prove that T (n) = O(n lg n) is an upper bound for the
recurrence T (n) = T (n/3) + T (2n/3) + O(n).
We show that T (n) ≤ dn lg n, where d is a suitable positive
constant. We have
as long as d ≥ c/(lg 3−(2/3))
Only induction
step for short
2023/2/22 24
Goto the master method
CHANGE OF VARIABLES (DOMAIN
TRANSFORMATIONS)
2023/2/22 25
Example 1 for Change of Variables
▪ Consider the recurrence T n = ቐ
𝑇
𝑛
2
+1, for 𝑛 > 1, 𝑛 𝑎 𝑝𝑜𝑤𝑒𝑟 𝑜𝑓 2
𝑇(1) = 1
Let
Let
2023/2/22 26
Example 2 for Change of Variables
Solve Induction example 4
▪ Consider the recurrence 𝑇(𝑛) = ൝
2𝑇(
𝑛
2
)+𝑛−1, for 𝑛 > 1, 𝑛 𝑎 𝑝𝑜𝑤𝑒𝑟 𝑜𝑓 2
𝑇(1) = 0
Let 𝑛 = 2𝑘
Then
Let
Then
2023/2/22 27
Example 3 for Change of Variables
▪ Consider the recurrence 𝑇(𝑛) = ൝
7𝑇(
𝑛
2
)+18(
𝑛
2
)2, for 𝑛 > 1, 𝑛 𝑎 𝑝𝑜𝑤𝑒𝑟 𝑜𝑓 2
𝑇(1) = 0
Let 𝑛 = 2𝑘
Let
Then
Then
2023/2/22 28
CHARACTERISTIC EQUATIONS
2023/2/22 30
Homogeneous Linear Recurrences
▪ Examples
2023/2/22 31
Example :Solve a homogeneous linear recurrence
▪ Consider the recurrence
𝑡𝑛 − 5𝑡𝑛−1 + 6𝑡𝑛−2 = 0 𝑓𝑜𝑟 𝑛 > 1
𝑡0 = 0
𝑡1 = 1
▪ Let 𝑡𝑛 = 𝑟𝑛
▪ Then 𝑡𝑛 − 5𝑡𝑛−1 + 6𝑡𝑛−2 = 𝑟𝑛 − 5𝑟𝑛−1 + 6𝑟𝑛−2
▪ Therefore, tn = rn is a solution to the recurrence if r is a root of 𝑟𝑛 − 5𝑟𝑛−1 + 6𝑟𝑛−2 = 0
▪ Because 𝑟𝑛 − 5𝑟𝑛−1 + 6𝑟𝑛−2 = 𝑟𝑛−2(𝑟2 − 5𝑟1 + 6𝑟0)
▪ the roots are r = 0, and the roots of 𝑟2 − 5𝑟 + 6=0
𝑟2 − 5𝑟 + 6 = (𝑟 − 3)(𝑟 − 2)
▪ The roots are r = 3 and r = 2.
▪ Then 𝑡𝑛 = 0, 3𝑛, and 2𝑛
2023/2/22 32
Example : Solve a homogeneous linear recurrence
▪ Consider the recurrence
𝑡𝑛 − 5𝑡𝑛−1 + 6𝑡𝑛−2 = 0 𝑓𝑜𝑟 𝑛 > 1
𝑡0 = 0
𝑡1 = 1
▪ Then 𝑡𝑛 = 𝑐13𝑛 + 𝑐22𝑛
▪ Consider The initial conditions 𝑡0 = 0, 𝑡1 = 1
▪ We have 𝑡0 = 𝑐130 + 𝑐220 = 0
𝑡1 = 𝑐131 + 𝑐221 = 1
▪ That is 𝑐1 + 𝑐2 = 0
3𝑐1 + 2𝑐2 = 1
▪ Therefore 𝑐1 = 1, 𝑐2 = −1
𝑡𝑛 = 3𝑛 − 2𝑛
Reminder:
If we had different initial conditions in the preceding
example, we would get a different solution.
A recurrence actually represents a class of functions,
one for each different assignment of initial conditions.
2023/2/22 33
Characteristic equation
2023/2/22 34
Theorem B.1 for k distinct roots for characteristic equation
2023/2/22 35
Example: k distinct roots
▪ Consider the recurrence
𝑡𝑛 − 3𝑡𝑛−1 − 4𝑡𝑛−2 = 0 𝑓𝑜𝑟 𝑛 > 1
𝑡0 = 0
𝑡1 = 1
2023/2/22 36
Example (Fibonacci sequence)
▪ Consider the recurrence
𝑡𝑛 − 𝑡𝑛−1 − 𝑡𝑛−2 = 0 𝑓𝑜𝑟 𝑛 > 1
𝑡0 = 0
𝑡1 = 1
2023/2/22 37
Theorem B.2 for a root of multiplicity m for characteristic
equation
2023/2/22 38
Example: a root of multiplicity
The roots are r = 1 and r = 3, and
r = 3 is a root of multiplicity 2.
▪ Consider the recurrence
𝑡𝑛 − 7𝑡𝑛−1 + 15𝑡𝑛−2 − 9𝑡𝑛−3 = 0 𝑓𝑜𝑟 𝑛 > 2
𝑡0 = 0
𝑡1 = 1 𝑡2 = 2
2023/2/22 39
Example : a root of multiplicity
▪ Consider the recurrence
𝑡𝑛 − 5𝑡𝑛−1 + 7𝑡𝑛−2 − 3𝑡𝑛−3 = 0 𝑓𝑜𝑟 𝑛 > 2
𝑡0 = 1
𝑡1 = 2 𝑡2 = 3
The roots are r = 3 and r = 1, and
r = 1 is a root of multiplicity 2.
2023/2/22 40
Nonhomogeneous Linear Recurrences
2023/2/22 41
▪ Consider the recurrence
𝑡𝑛 − 3𝑡𝑛−1 = 4𝑛 𝑓𝑜𝑟 𝑛 > 1
𝑡0 = 0
𝑡1 = 4
Example: Solve a nonhomogeneous linear recurrence
𝑡𝑛−1 − 3𝑡𝑛−2 = 4𝑛−1
𝑡𝑛
4
− 3
𝑡𝑛−1
4
= 4𝑛−1
1. Replace n with n − 1 in the original recurrence
2. Divide the original recurrence by 4
3. Combine the above two results
𝑡𝑛
4
− 7
𝑡𝑛−1
4
+ 3𝑡𝑛−2 = 0
4. Multiply the result of (3) by 4
𝑡𝑛 − 7𝑡𝑛−1 + 12𝑡𝑛−2 = 0
5. Solve a homogeneous linear recurrence
𝑟2 − 7𝑟 + 12 = 𝑟 − 3 𝑟 − 4 = 0
𝑟 = 3 𝑟 = 4
𝑡𝑛 = 𝑐13𝑛 + 𝑐24𝑛
use the initial conditions 𝑡0 = 0 and 𝑡1 = 4
𝑡𝑛 = 4𝑛+1 − 4(3𝑛)
2023/2/22 42
Theorem for Nonhomogeneous Linear Recurrences
2023/2/22 43
Example 1 for Theorem B.2 & Theorem B.3
▪ Consider the recurrence
𝑡𝑛 − 3𝑡𝑛−1 = 4𝑛(2𝑛 + 1) 𝑓𝑜𝑟 𝑛 > 1
𝑡0 = 0
𝑡1 = 12
2023/2/22 44
Example 2 for Theorem B.2 & Theorem B.3
▪ Consider the recurrence
𝑡𝑛 − 𝑡𝑛−1 = 𝑛 − 1 𝑓𝑜𝑟 𝑛 > 0
𝑡0 = 0
2023/2/22 45
Unfinished Example for Theorem B.3
▪ Consider the recurrence
𝑡𝑛 − 2𝑡𝑛−1 = 𝑛 +2𝑛 𝑓𝑜𝑟 𝑛 > 1
𝑡1 = 0
2023/2/22 46
EXTENDING RESULTS
FOR N, A POWER OF A
POSITIVE CONSTANT B,
TO N IN GENERAL
Strictly increasing
▪ Many of the functions we encounter in algorithm analysis are strictly increasing
for nonnegative values of n.
▪ For example, lg n, n, n lg n, n2, and 2n are all strictly increasing as long as n is
nonnegative.
2023/2/22 48
Nondecreasing
▪ Any strictly increasing function is nondecreasing, but a function that can level out
is nondecreasing without being strictly increasing.
2023/2/22 49
Eventually nondecreasing
▪ Any nondecreasing function is eventually nondecreasing.
2023/2/22 50
Smooth
Example: The functions lg n, n, n lg n, and nk, where k ≥ 0, are all smooth.
Example: Proof for lg n:
Example: The function 2nis not smooth
2023/2/22 51
Theorem for Generalize results obtained for n a power of b
2023/2/22 52
Example for Theorem B.4
▪ Consider the recurrence T n = ቐ
𝑇(
𝑛
2
)+1, for 𝑛 > 1
𝑇(1) = 1
Because lg n is smooth, we need only show that T (n) is
eventually nondecreasing in order to apply Theorem B.4
to conclude that
2023/2/22 53
Prove: is eventually nondecreasing
T n = ቐ
𝑇(
𝑛
2
)+1, for 𝑛 > 1
𝑇(1) = 1
2023/2/22 54
THE MASTER METHOD
支配理論/天下無敵法/老大定理
2023/2/22 55
The master theorem
2023/2/22 56
Examples for The master theorem
2023/2/22 59
Examples for The master theorem
2023/2/22 60
A Counterexample for The master theorem
2023/2/22 61
徵求
程式
One example (2022/2/22 add)
2023/2/22 62
https://stackoverflow.com/questions/4317414/polynomial-time-and-exponential-
time
References
▪ Introduction to Algorithms 3/e (Thomas H. Cormen, etc.;MIT, 開發圖書代理 2009)
(4/e 2022)
▪ Foundations of Algorithms 5/e( Neapolitan, Richard E.; Jones and Bartlett P ; 開發
圖書代理2014)
▪ 演算法: 使用C++ 虛擬碼 (蔡宗翰, 碁峰圖書出版2017)
2023/2/22 64

More Related Content

Similar to P1-07-Recurrences.pdf

Direct solution of sparse network equations by optimally ordered triangular f...
Direct solution of sparse network equations by optimally ordered triangular f...Direct solution of sparse network equations by optimally ordered triangular f...
Direct solution of sparse network equations by optimally ordered triangular f...Dimas Ruliandi
 
2.6 Other Types of Equations
2.6 Other Types of Equations2.6 Other Types of Equations
2.6 Other Types of Equationssmiller5
 
0.7 Radical Expressions
0.7 Radical Expressions0.7 Radical Expressions
0.7 Radical Expressionssmiller5
 
Laplace equation
Laplace equationLaplace equation
Laplace equationalexkhan129
 
Recurrences
RecurrencesRecurrences
RecurrencesDEVTYPE
 
B.tech ii unit-4 material vector differentiation
B.tech ii unit-4 material vector differentiationB.tech ii unit-4 material vector differentiation
B.tech ii unit-4 material vector differentiationRai University
 
Btech_II_ engineering mathematics_unit3
Btech_II_ engineering mathematics_unit3Btech_II_ engineering mathematics_unit3
Btech_II_ engineering mathematics_unit3Rai University
 
Lesson 10 techniques of integration
Lesson 10 techniques of integrationLesson 10 techniques of integration
Lesson 10 techniques of integrationLawrence De Vera
 
MATH PPT (MC-I)-2.pptx
MATH PPT (MC-I)-2.pptxMATH PPT (MC-I)-2.pptx
MATH PPT (MC-I)-2.pptxitzsudipto99
 
Analysis Of Algorithms Ii
Analysis Of Algorithms IiAnalysis Of Algorithms Ii
Analysis Of Algorithms IiSri Prasanna
 
Unit-1 Basic Concept of Algorithm.pptx
Unit-1 Basic Concept of Algorithm.pptxUnit-1 Basic Concept of Algorithm.pptx
Unit-1 Basic Concept of Algorithm.pptxssuser01e301
 
Alegebra Powers Substitution
Alegebra Powers SubstitutionAlegebra Powers Substitution
Alegebra Powers SubstitutionPassy World
 
Business Math Chapter 3
Business Math Chapter 3Business Math Chapter 3
Business Math Chapter 3Nazrin Nazdri
 
Semana 27 funciones exponenciales álgebra uni ccesa007
Semana 27 funciones exponenciales álgebra uni ccesa007Semana 27 funciones exponenciales álgebra uni ccesa007
Semana 27 funciones exponenciales álgebra uni ccesa007Demetrio Ccesa Rayme
 
Elementary Differential Equations 11th Edition Boyce Solutions Manual
Elementary Differential Equations 11th Edition Boyce Solutions ManualElementary Differential Equations 11th Edition Boyce Solutions Manual
Elementary Differential Equations 11th Edition Boyce Solutions ManualMiriamKennedys
 
Trig substitution
Trig substitutionTrig substitution
Trig substitutiondynx24
 

Similar to P1-07-Recurrences.pdf (20)

Direct solution of sparse network equations by optimally ordered triangular f...
Direct solution of sparse network equations by optimally ordered triangular f...Direct solution of sparse network equations by optimally ordered triangular f...
Direct solution of sparse network equations by optimally ordered triangular f...
 
2.6 Other Types of Equations
2.6 Other Types of Equations2.6 Other Types of Equations
2.6 Other Types of Equations
 
0.7 Radical Expressions
0.7 Radical Expressions0.7 Radical Expressions
0.7 Radical Expressions
 
Laplace equation
Laplace equationLaplace equation
Laplace equation
 
Recurrences
RecurrencesRecurrences
Recurrences
 
B.tech ii unit-4 material vector differentiation
B.tech ii unit-4 material vector differentiationB.tech ii unit-4 material vector differentiation
B.tech ii unit-4 material vector differentiation
 
Recurrences
RecurrencesRecurrences
Recurrences
 
Btech_II_ engineering mathematics_unit3
Btech_II_ engineering mathematics_unit3Btech_II_ engineering mathematics_unit3
Btech_II_ engineering mathematics_unit3
 
SMT1105-1.pdf
SMT1105-1.pdfSMT1105-1.pdf
SMT1105-1.pdf
 
Lesson 10 techniques of integration
Lesson 10 techniques of integrationLesson 10 techniques of integration
Lesson 10 techniques of integration
 
TABREZ KHAN.ppt
TABREZ KHAN.pptTABREZ KHAN.ppt
TABREZ KHAN.ppt
 
MATH PPT (MC-I)-2.pptx
MATH PPT (MC-I)-2.pptxMATH PPT (MC-I)-2.pptx
MATH PPT (MC-I)-2.pptx
 
Analysis Of Algorithms Ii
Analysis Of Algorithms IiAnalysis Of Algorithms Ii
Analysis Of Algorithms Ii
 
Unit-1 Basic Concept of Algorithm.pptx
Unit-1 Basic Concept of Algorithm.pptxUnit-1 Basic Concept of Algorithm.pptx
Unit-1 Basic Concept of Algorithm.pptx
 
Alegebra Powers Substitution
Alegebra Powers SubstitutionAlegebra Powers Substitution
Alegebra Powers Substitution
 
Business Math Chapter 3
Business Math Chapter 3Business Math Chapter 3
Business Math Chapter 3
 
Semana 27 funciones exponenciales álgebra uni ccesa007
Semana 27 funciones exponenciales álgebra uni ccesa007Semana 27 funciones exponenciales álgebra uni ccesa007
Semana 27 funciones exponenciales álgebra uni ccesa007
 
Elementary Differential Equations 11th Edition Boyce Solutions Manual
Elementary Differential Equations 11th Edition Boyce Solutions ManualElementary Differential Equations 11th Edition Boyce Solutions Manual
Elementary Differential Equations 11th Edition Boyce Solutions Manual
 
Trig substitution
Trig substitutionTrig substitution
Trig substitution
 
3.pdf
3.pdf3.pdf
3.pdf
 

Recently uploaded

social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingTeacherCyreneCayanan
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...PsychoTech Services
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 

Recently uploaded (20)

social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 

P1-07-Recurrences.pdf

  • 2. Recursive Thinking § Recurrence Relations (Recurrences) § Closed-Form Solutions and Induction § Recursive Definitions § Proof by Induction 2023/2/22 2
  • 4. Recurrence Relations A well-defined recurrence relation needs a nonrecursive base case that gives at least one value of the function explicitly. recursive part 2023/2/22 4
  • 5. Binary search (of sorted array) https://en.wikipedia.org/wiki/Binary_search_algorithm A tree representing binary search. The array being searched here is [20,30,40,50,80,90,100] and the target value is 40. https://www.geeksforgeeks.org/binary-search/ The array being searched here is [2,5,8,12,16,23,38,56,72,91] and the target value is 23. 𝑇 𝑛 = ቐ Θ(1) 𝑖𝑓 𝑛 = 1, 𝑇 𝑛 2 + Θ(1) 𝑖𝑓 𝑛 > 1. ▪ The recurrence describing the worst- case running time of Binary search ▪ Example ▪ Example 2023/2/22 5
  • 6. MERGE-SORT ▪ The recurrence describing the worst-case running time of MERGE-SORT https://ithelp.ithome.com.tw/articles/10278179 利用30 10 40 70 50 90 60 20由小到大排序。 ▪ Example 2023/2/22 6
  • 7. Fibonacci Numbers A tiling with squares whose side lengths are successive Fibonacci numbers: 1, 1, 2, 3, 5, 8, 13 and 21. https://en.wikipedia.org/wiki/Fibonacci_number https://betterprogramming.pub/ the-beauty-of-the-fibonacci- sequence-c6f95674b94e ▪ Examples 2023/2/22 7
  • 8. Solving Recurrence Equations ▪ Guess and proof by Induction ▪ Substitution method ▪ Recursion-tree method ▪ Change of Variables (Domain Transformations) ▪ Characteristic Equations ▪ Extending Results for n, a Power of a Positive Constant b, to n in General ▪ Master method 2023/2/22 8
  • 9. GUESS AND PROOF BY INDUCTION 2023/2/22 9
  • 10. Example 1 for Guess and proof by Induction ▪ Consider the recurrence 𝑡𝑛 = ቊ 𝑡𝑛−1+1, for 𝑛 > 0 𝑡0 = 0 ▪ Guess ▪ Induction proof: 2023/2/22 10
  • 11. Example 2 for Guess and proof by Induction ▪ Consider the recurrence 𝑡𝑛 = ൝ 𝑡 Τ 𝑛 2 +1, for 𝑛 > 1, 𝑛 𝑎 𝑝𝑜𝑤𝑒𝑟 𝑜𝑓 2 𝑡1 = 1 ▪ Guess ▪ Induction proof: 2023/2/22 11
  • 12. Example 3 for Guess and proof by Induction ▪ Consider the recurrence 𝑡𝑛 = ൝ 7𝑡 Τ 𝑛 2 , for 𝑛 > 1, 𝑛 𝑎 𝑝𝑜𝑤𝑒𝑟 𝑜𝑓 2 𝑡1 = 1 ▪ Guess ▪ Induction proof: 2023/2/22 12
  • 13. Example 4 (unfinished) for Guess and proof by Induction ▪ Consider the recurrence 𝑡𝑛 = ൝ 2𝑡 Τ 𝑛 2 +𝑛−1, for 𝑛 > 1, 𝑛 𝑎 𝑝𝑜𝑤𝑒𝑟 𝑜𝑓 2 𝑡1 = 0 ▪ There is no obvious candidate solution suggested by these values. Learn more techniques!! Induction can only verify that a solution is correct!! 2023/2/22 13
  • 14. SUBSTITUTION METHOD (代換法) In the substitution method, we guess a bound and then use mathematical induction to prove our guess correct. 2023/2/22 14
  • 15. Example 1 of The substitution method ▪ Consider the recurrence 𝑡𝑛 = ቊ 𝑡𝑛−1+n, for 𝑛 > 1 𝑡1 = 1 2023/2/22 16
  • 16. Example 2 of The substitution method ▪ Consider the recurrence 𝑡𝑛 = ቐ 𝑡𝑛−1+ 2 𝑛 , for 𝑛 > 1 𝑡1 = 0 2023/2/22 17
  • 18. Height, Depth and Level of a Tree (2022/2/22 add ) 2023/2/22 19 http://typeocaml.com/2014/11/26/height-depth-and-level-of-a-tree/ Height of node – The height of a node is the number of edges on the longest downward path between that node and a leaf. Depth –The depth of a node is the number of edges from the node to the tree's root node. Level – The level of a node is defined by 1 + the number of connections between the node and the root.
  • 19. Example 1 for recursion tree The construction of a recursion tree for the recurrence T (n) = 2T (n/2) + cn. In a recursion tree, each node represents the cost of a single subproblem somewhere in the set of recursive function invocations. A recursion tree is best used to generate a good guess, which is then verified by the mathematical induction . 2023/2/22 20
  • 20. Example 2 for recursion tree The construction of a recursion tree for the recurrence T (n) = 3T (n/4) + cn2. 2023/2/22 21
  • 21. Use the substitution method to verify that our guess was correct for example 2 Prove that T (n) = O(n2) is an upper bound for the recurrence T (n) = 3T (n/4) + cn2. Only induction step for short 2023/2/22 22
  • 22. Example 3 for recursion tree The construction of a recursion tree for the recurrence T (n) = T (n/3) + T (2n/3) + O(n). The longest path from the root to a leaf is n→(2/3)n→(2/3)2n→· · ·→1. Since (2/3)kn = 1 when k = log3/2 n, the height of the tree is log3/2 n. 2023/2/22 23
  • 23. Use the substitution method to verify that our guess was correct for example 2 Prove that T (n) = O(n lg n) is an upper bound for the recurrence T (n) = T (n/3) + T (2n/3) + O(n). We show that T (n) ≤ dn lg n, where d is a suitable positive constant. We have as long as d ≥ c/(lg 3−(2/3)) Only induction step for short 2023/2/22 24 Goto the master method
  • 24. CHANGE OF VARIABLES (DOMAIN TRANSFORMATIONS) 2023/2/22 25
  • 25. Example 1 for Change of Variables ▪ Consider the recurrence T n = ቐ 𝑇 𝑛 2 +1, for 𝑛 > 1, 𝑛 𝑎 𝑝𝑜𝑤𝑒𝑟 𝑜𝑓 2 𝑇(1) = 1 Let Let 2023/2/22 26
  • 26. Example 2 for Change of Variables Solve Induction example 4 ▪ Consider the recurrence 𝑇(𝑛) = ൝ 2𝑇( 𝑛 2 )+𝑛−1, for 𝑛 > 1, 𝑛 𝑎 𝑝𝑜𝑤𝑒𝑟 𝑜𝑓 2 𝑇(1) = 0 Let 𝑛 = 2𝑘 Then Let Then 2023/2/22 27
  • 27. Example 3 for Change of Variables ▪ Consider the recurrence 𝑇(𝑛) = ൝ 7𝑇( 𝑛 2 )+18( 𝑛 2 )2, for 𝑛 > 1, 𝑛 𝑎 𝑝𝑜𝑤𝑒𝑟 𝑜𝑓 2 𝑇(1) = 0 Let 𝑛 = 2𝑘 Let Then Then 2023/2/22 28
  • 29. Homogeneous Linear Recurrences ▪ Examples 2023/2/22 31
  • 30. Example :Solve a homogeneous linear recurrence ▪ Consider the recurrence 𝑡𝑛 − 5𝑡𝑛−1 + 6𝑡𝑛−2 = 0 𝑓𝑜𝑟 𝑛 > 1 𝑡0 = 0 𝑡1 = 1 ▪ Let 𝑡𝑛 = 𝑟𝑛 ▪ Then 𝑡𝑛 − 5𝑡𝑛−1 + 6𝑡𝑛−2 = 𝑟𝑛 − 5𝑟𝑛−1 + 6𝑟𝑛−2 ▪ Therefore, tn = rn is a solution to the recurrence if r is a root of 𝑟𝑛 − 5𝑟𝑛−1 + 6𝑟𝑛−2 = 0 ▪ Because 𝑟𝑛 − 5𝑟𝑛−1 + 6𝑟𝑛−2 = 𝑟𝑛−2(𝑟2 − 5𝑟1 + 6𝑟0) ▪ the roots are r = 0, and the roots of 𝑟2 − 5𝑟 + 6=0 𝑟2 − 5𝑟 + 6 = (𝑟 − 3)(𝑟 − 2) ▪ The roots are r = 3 and r = 2. ▪ Then 𝑡𝑛 = 0, 3𝑛, and 2𝑛 2023/2/22 32
  • 31. Example : Solve a homogeneous linear recurrence ▪ Consider the recurrence 𝑡𝑛 − 5𝑡𝑛−1 + 6𝑡𝑛−2 = 0 𝑓𝑜𝑟 𝑛 > 1 𝑡0 = 0 𝑡1 = 1 ▪ Then 𝑡𝑛 = 𝑐13𝑛 + 𝑐22𝑛 ▪ Consider The initial conditions 𝑡0 = 0, 𝑡1 = 1 ▪ We have 𝑡0 = 𝑐130 + 𝑐220 = 0 𝑡1 = 𝑐131 + 𝑐221 = 1 ▪ That is 𝑐1 + 𝑐2 = 0 3𝑐1 + 2𝑐2 = 1 ▪ Therefore 𝑐1 = 1, 𝑐2 = −1 𝑡𝑛 = 3𝑛 − 2𝑛 Reminder: If we had different initial conditions in the preceding example, we would get a different solution. A recurrence actually represents a class of functions, one for each different assignment of initial conditions. 2023/2/22 33
  • 33. Theorem B.1 for k distinct roots for characteristic equation 2023/2/22 35
  • 34. Example: k distinct roots ▪ Consider the recurrence 𝑡𝑛 − 3𝑡𝑛−1 − 4𝑡𝑛−2 = 0 𝑓𝑜𝑟 𝑛 > 1 𝑡0 = 0 𝑡1 = 1 2023/2/22 36
  • 35. Example (Fibonacci sequence) ▪ Consider the recurrence 𝑡𝑛 − 𝑡𝑛−1 − 𝑡𝑛−2 = 0 𝑓𝑜𝑟 𝑛 > 1 𝑡0 = 0 𝑡1 = 1 2023/2/22 37
  • 36. Theorem B.2 for a root of multiplicity m for characteristic equation 2023/2/22 38
  • 37. Example: a root of multiplicity The roots are r = 1 and r = 3, and r = 3 is a root of multiplicity 2. ▪ Consider the recurrence 𝑡𝑛 − 7𝑡𝑛−1 + 15𝑡𝑛−2 − 9𝑡𝑛−3 = 0 𝑓𝑜𝑟 𝑛 > 2 𝑡0 = 0 𝑡1 = 1 𝑡2 = 2 2023/2/22 39
  • 38. Example : a root of multiplicity ▪ Consider the recurrence 𝑡𝑛 − 5𝑡𝑛−1 + 7𝑡𝑛−2 − 3𝑡𝑛−3 = 0 𝑓𝑜𝑟 𝑛 > 2 𝑡0 = 1 𝑡1 = 2 𝑡2 = 3 The roots are r = 3 and r = 1, and r = 1 is a root of multiplicity 2. 2023/2/22 40
  • 40. ▪ Consider the recurrence 𝑡𝑛 − 3𝑡𝑛−1 = 4𝑛 𝑓𝑜𝑟 𝑛 > 1 𝑡0 = 0 𝑡1 = 4 Example: Solve a nonhomogeneous linear recurrence 𝑡𝑛−1 − 3𝑡𝑛−2 = 4𝑛−1 𝑡𝑛 4 − 3 𝑡𝑛−1 4 = 4𝑛−1 1. Replace n with n − 1 in the original recurrence 2. Divide the original recurrence by 4 3. Combine the above two results 𝑡𝑛 4 − 7 𝑡𝑛−1 4 + 3𝑡𝑛−2 = 0 4. Multiply the result of (3) by 4 𝑡𝑛 − 7𝑡𝑛−1 + 12𝑡𝑛−2 = 0 5. Solve a homogeneous linear recurrence 𝑟2 − 7𝑟 + 12 = 𝑟 − 3 𝑟 − 4 = 0 𝑟 = 3 𝑟 = 4 𝑡𝑛 = 𝑐13𝑛 + 𝑐24𝑛 use the initial conditions 𝑡0 = 0 and 𝑡1 = 4 𝑡𝑛 = 4𝑛+1 − 4(3𝑛) 2023/2/22 42
  • 41. Theorem for Nonhomogeneous Linear Recurrences 2023/2/22 43
  • 42. Example 1 for Theorem B.2 & Theorem B.3 ▪ Consider the recurrence 𝑡𝑛 − 3𝑡𝑛−1 = 4𝑛(2𝑛 + 1) 𝑓𝑜𝑟 𝑛 > 1 𝑡0 = 0 𝑡1 = 12 2023/2/22 44
  • 43. Example 2 for Theorem B.2 & Theorem B.3 ▪ Consider the recurrence 𝑡𝑛 − 𝑡𝑛−1 = 𝑛 − 1 𝑓𝑜𝑟 𝑛 > 0 𝑡0 = 0 2023/2/22 45
  • 44. Unfinished Example for Theorem B.3 ▪ Consider the recurrence 𝑡𝑛 − 2𝑡𝑛−1 = 𝑛 +2𝑛 𝑓𝑜𝑟 𝑛 > 1 𝑡1 = 0 2023/2/22 46
  • 45. EXTENDING RESULTS FOR N, A POWER OF A POSITIVE CONSTANT B, TO N IN GENERAL
  • 46. Strictly increasing ▪ Many of the functions we encounter in algorithm analysis are strictly increasing for nonnegative values of n. ▪ For example, lg n, n, n lg n, n2, and 2n are all strictly increasing as long as n is nonnegative. 2023/2/22 48
  • 47. Nondecreasing ▪ Any strictly increasing function is nondecreasing, but a function that can level out is nondecreasing without being strictly increasing. 2023/2/22 49
  • 48. Eventually nondecreasing ▪ Any nondecreasing function is eventually nondecreasing. 2023/2/22 50
  • 49. Smooth Example: The functions lg n, n, n lg n, and nk, where k ≥ 0, are all smooth. Example: Proof for lg n: Example: The function 2nis not smooth 2023/2/22 51
  • 50. Theorem for Generalize results obtained for n a power of b 2023/2/22 52
  • 51. Example for Theorem B.4 ▪ Consider the recurrence T n = ቐ 𝑇( 𝑛 2 )+1, for 𝑛 > 1 𝑇(1) = 1 Because lg n is smooth, we need only show that T (n) is eventually nondecreasing in order to apply Theorem B.4 to conclude that 2023/2/22 53
  • 52. Prove: is eventually nondecreasing T n = ቐ 𝑇( 𝑛 2 )+1, for 𝑛 > 1 𝑇(1) = 1 2023/2/22 54
  • 55. Examples for The master theorem 2023/2/22 59
  • 56. Examples for The master theorem 2023/2/22 60
  • 57. A Counterexample for The master theorem 2023/2/22 61 徵求 程式
  • 58. One example (2022/2/22 add) 2023/2/22 62 https://stackoverflow.com/questions/4317414/polynomial-time-and-exponential- time
  • 59. References ▪ Introduction to Algorithms 3/e (Thomas H. Cormen, etc.;MIT, 開發圖書代理 2009) (4/e 2022) ▪ Foundations of Algorithms 5/e( Neapolitan, Richard E.; Jones and Bartlett P ; 開發 圖書代理2014) ▪ 演算法: 使用C++ 虛擬碼 (蔡宗翰, 碁峰圖書出版2017) 2023/2/22 64