Recurrent Problem
Motivation
We will explore three sample problems that give a feel for what’s to come.
They have two traits in common:
 Investigated repeatedly
 Solutions all use the idea of recurrence
• Solution to each problem depends on the solutions to smaller instances of the same problem.
Problems with Recursive Solution
Easy to solve small problem.
Refers to previous steps and so on becomes hard to solve problems that are
relatively large.
Closed Form
An expression that can be expressed analytically in terms of a finite
number of certain "well-known" functions.
 Elementary Functions
o Constants
o One variable
o Finite number of exponentials or logarithms or roots of polynomial
o Four elementary operations (+ – × ÷).
Steps to Solve A Problem
Look at small cases.
Find and prove a mathematical expression for the quantity of interest.
Recurrence Relation.
Find and prove a closed form for our mathematical expression. Prove
the closed form using mathematical induction
Recurrent Problems
The Tower of Hanoi
The Lines in The Plane
The Josephus Problem
Tower of Hanoi Problem
Invented by the French mathematician Edouard Lucas in 1883.
Given a tower of n disks, initially stacked in decreasing size on one of three pegs.
The objective is
 Transfer the entire tower to one of the other pegs.
 Move only one disk at a time.
 Never move a larger one onto a smaller.
Tower of Hanoi : 3 Disks START
BEG AUX END
Tower of Hanoi : 3 Disks FINISH
BEG AUX END
Tower of Hanoi : Recursive Solution
Let’s call the three peg BEG(Source), AUX(Auxiliary) and END(Destination).
1) Move the top N – 1 disks from the BEG to AUX tower using END
2) Move the Nth disk from BEG to END tower
3) Move the N – 1 disks from AUX tower to END tower using BEG
Tower of Hanoi : 3 Disks
BEG AUX END
Move n-1 disks from BEG to AUX using END
Tower of Hanoi : 3 Disks
BEG AUX END
Tower of Hanoi : 3 Disks
BEG AUX END
Tower of Hanoi : 3 Disks
BEG AUX END
Move largest one from BEG to END
Tower of Hanoi : 3 Disks
BEG AUX END
Move n-1 disks from AUX to END using BEG
Tower of Hanoi : 3 Disks
BEG AUX END
Tower of Hanoi : 3 Disks
BEG AUX END
Tower of Hanoi : 3 Disks
BEG AUX END
Tower of Hanoi : No. of Moves, Tn
• for 1 disk it takes 1 move to transfer 1 disk from BEG to END;
• for 2 disks, it will take 3 moves: 2 Tn-1 + 1 = 2(1) + 1 = 3
• for 3 disks, it will take 7 moves: 2 Tn-1 + 1 = 2(3) + 1 = 7
• for 4 disks, it will take 15 moves: 2 Tn-1 + 1 = 2(7) + 1 = 15
• for 5 disks, it will take 31 moves: 2 Tn-1 + 1 = 2(15) + 1 = 31
• for 6 disks... ?
Tower of Hanoi : No. of Moves, Tn
• Explicit Pattern
Number of Disks Number of Moves
1 1
2 3
3 7
4 15
5 31
T0 = 0
Tn = 2 Tn-1 + 1,n>0
Tower of Hanoi : Recursive Solution Difficulties
T7 = ?
T7 = 2 T6 + 1
= 2(2 T5 + 1) + 1
= 4(2 T4 + 1) + 3
= 8(2 T3 + 1) + 7
= 16(2 T2 + 1) + 15
= 32(2 T1 + 1) + 31
= 64(2 T0 + 1) + 63
= 64 × 0 + 64+ 63
= 127
T50 = ?
T50 = 2 T49 + 1
= 2(2 T48 + 1) + 1
= 4(2 T47 + 1) + 3
= 8(2 T46 + 1) + 7
……………………….
=?
Tower of Hanoi : Finding Closed Form
• Explicit Pattern
Number of Disks Number of Moves
1 1
2 3
3 7
4 15
5 31
• Powers of two help reveal the pattern
Number of Disks Number of Moves
1 21 - 1 = 2 - 1 = 1
2 22 - 1 = 4 - 1 = 3
3 23 - 1 = 8 - 1 = 7
4 24 - 1 = 16 - 1 = 15
5 25 - 1 = 32 - 1 = 31
Tn = 2 n - 1
A Closed Form
Tower of Hanoi : Proving Closed Form
Basis : For n= 0, T0 = 2n – 1 = 20 – 1 = 0
Induction : Let for n = n-1 the expression is true, then Tn-1 = 2n-1 – 1
Hypothesis : For n = n ,
Tn = 2 Tn-1 + 1
= 2 (2n-1 – 1 ) + 1
= 2n-1+1 – 2 + 1
= 2n – 1
Lines in The Plane Problem
Popularly: How many slices of pizza can a person obtain by making n
straight cuts with a pizza knife?
Academically: What is the maximum number Ln of regions defined by n
lines in the plane?
Lines in The Plane : Recursive Solution
Draw lines so that they intersect each others
Calculate maximum number of regions created by lines
Lines in The Plane : N = 0
L0 = 1
Lines in The Plane : N = 1
L1 = 2
Lines in The Plane : N = 2
L2 = 4
Lines in The Plane : N = 3
L3 = 7
Lines in The Plane : N = 4
L4 = 11
Lines in The Plane : Maximum No. of Regions, Ln
• for 0 line it creates 1 region;
• for 1 lines, it creates 2 region; : Ln-1 + n = 1 + 1 = 2
• for 2 lines, it creates 4 region; : Ln-1 + n = 2 + 2 = 4
• for 3 lines, it will take 7 region: Ln-1 + n = 4 + 3 = 7
• for 4 lines, it will take 10 region: Ln-1 + n = 7 + 4 = 11
• for 5 lines... ?
L0 = 1
Ln = Ln-1 + n, n>0
Lines in The Plane : Recursive Solution Difficulties
L7 = ?
L7 = L6 + 7
= L5 + 6 + 7
= L4 + 5+ 13
= L3 + 4 + 18
= L2 + 3 + 22
= L1 + 2 + 25
= L0 + 1 + 27
= 1+ 28
= 29
L50 = ?
L50 = L49 + 50
= L48 + 49+ 50
= L47 + 48+ 99
= L46 + 47 +14 7
……………………….
=?
Lines in The Plane: Finding Closed Form
Ln = Ln-1 + n
= Ln-2 + (n-1) + n
= Ln-3 + (n-2) + (n-1) + n
= Ln-2 + (n-3) + (n-2) + (n-1) + n
……………………..
= L0 + 1 + 2 + …… + (n-3) + (n-2) + (n-1) + n
= 1 +
𝒏(𝒏+𝟏)
𝟐
Lines in The Plane : Proving Closed Form
Basis : For n= 0, L0 = 1 +
𝟎(𝟎+𝟏)
𝟐
= 1
Induction : Let for n = n-1 the expression is true, then Ln-1 = 1 +
𝒏(𝒏 − 𝟏)
𝟐
Hypothesis : For n = n ,
Ln = Ln-1 + n
= 1 +
𝒏(𝒏 − 𝟏)
𝟐
+ n
= 1 +
𝒏𝟐
− 𝒏 + 𝟐𝒏
𝟐
= 1 +
𝒏𝟐
+ 𝒏
𝟐
= 1 +
𝒏(𝒏 + 𝟏)
𝟐
Josephus Problem
Do it Yourself
Solve Exercises
The End

Recurrent Problem in Discrete Mathmatics.pptx

  • 1.
  • 2.
    Motivation We will explorethree sample problems that give a feel for what’s to come. They have two traits in common:  Investigated repeatedly  Solutions all use the idea of recurrence • Solution to each problem depends on the solutions to smaller instances of the same problem.
  • 3.
    Problems with RecursiveSolution Easy to solve small problem. Refers to previous steps and so on becomes hard to solve problems that are relatively large.
  • 4.
    Closed Form An expressionthat can be expressed analytically in terms of a finite number of certain "well-known" functions.  Elementary Functions o Constants o One variable o Finite number of exponentials or logarithms or roots of polynomial o Four elementary operations (+ – × ÷).
  • 5.
    Steps to SolveA Problem Look at small cases. Find and prove a mathematical expression for the quantity of interest. Recurrence Relation. Find and prove a closed form for our mathematical expression. Prove the closed form using mathematical induction
  • 6.
    Recurrent Problems The Towerof Hanoi The Lines in The Plane The Josephus Problem
  • 7.
    Tower of HanoiProblem Invented by the French mathematician Edouard Lucas in 1883. Given a tower of n disks, initially stacked in decreasing size on one of three pegs. The objective is  Transfer the entire tower to one of the other pegs.  Move only one disk at a time.  Never move a larger one onto a smaller.
  • 8.
    Tower of Hanoi: 3 Disks START BEG AUX END
  • 9.
    Tower of Hanoi: 3 Disks FINISH BEG AUX END
  • 10.
    Tower of Hanoi: Recursive Solution Let’s call the three peg BEG(Source), AUX(Auxiliary) and END(Destination). 1) Move the top N – 1 disks from the BEG to AUX tower using END 2) Move the Nth disk from BEG to END tower 3) Move the N – 1 disks from AUX tower to END tower using BEG
  • 11.
    Tower of Hanoi: 3 Disks BEG AUX END Move n-1 disks from BEG to AUX using END
  • 12.
    Tower of Hanoi: 3 Disks BEG AUX END
  • 13.
    Tower of Hanoi: 3 Disks BEG AUX END
  • 14.
    Tower of Hanoi: 3 Disks BEG AUX END Move largest one from BEG to END
  • 15.
    Tower of Hanoi: 3 Disks BEG AUX END Move n-1 disks from AUX to END using BEG
  • 16.
    Tower of Hanoi: 3 Disks BEG AUX END
  • 17.
    Tower of Hanoi: 3 Disks BEG AUX END
  • 18.
    Tower of Hanoi: 3 Disks BEG AUX END
  • 19.
    Tower of Hanoi: No. of Moves, Tn • for 1 disk it takes 1 move to transfer 1 disk from BEG to END; • for 2 disks, it will take 3 moves: 2 Tn-1 + 1 = 2(1) + 1 = 3 • for 3 disks, it will take 7 moves: 2 Tn-1 + 1 = 2(3) + 1 = 7 • for 4 disks, it will take 15 moves: 2 Tn-1 + 1 = 2(7) + 1 = 15 • for 5 disks, it will take 31 moves: 2 Tn-1 + 1 = 2(15) + 1 = 31 • for 6 disks... ?
  • 20.
    Tower of Hanoi: No. of Moves, Tn • Explicit Pattern Number of Disks Number of Moves 1 1 2 3 3 7 4 15 5 31 T0 = 0 Tn = 2 Tn-1 + 1,n>0
  • 21.
    Tower of Hanoi: Recursive Solution Difficulties T7 = ? T7 = 2 T6 + 1 = 2(2 T5 + 1) + 1 = 4(2 T4 + 1) + 3 = 8(2 T3 + 1) + 7 = 16(2 T2 + 1) + 15 = 32(2 T1 + 1) + 31 = 64(2 T0 + 1) + 63 = 64 × 0 + 64+ 63 = 127 T50 = ? T50 = 2 T49 + 1 = 2(2 T48 + 1) + 1 = 4(2 T47 + 1) + 3 = 8(2 T46 + 1) + 7 ………………………. =?
  • 22.
    Tower of Hanoi: Finding Closed Form • Explicit Pattern Number of Disks Number of Moves 1 1 2 3 3 7 4 15 5 31 • Powers of two help reveal the pattern Number of Disks Number of Moves 1 21 - 1 = 2 - 1 = 1 2 22 - 1 = 4 - 1 = 3 3 23 - 1 = 8 - 1 = 7 4 24 - 1 = 16 - 1 = 15 5 25 - 1 = 32 - 1 = 31 Tn = 2 n - 1 A Closed Form
  • 23.
    Tower of Hanoi: Proving Closed Form Basis : For n= 0, T0 = 2n – 1 = 20 – 1 = 0 Induction : Let for n = n-1 the expression is true, then Tn-1 = 2n-1 – 1 Hypothesis : For n = n , Tn = 2 Tn-1 + 1 = 2 (2n-1 – 1 ) + 1 = 2n-1+1 – 2 + 1 = 2n – 1
  • 24.
    Lines in ThePlane Problem Popularly: How many slices of pizza can a person obtain by making n straight cuts with a pizza knife? Academically: What is the maximum number Ln of regions defined by n lines in the plane?
  • 25.
    Lines in ThePlane : Recursive Solution Draw lines so that they intersect each others Calculate maximum number of regions created by lines
  • 26.
    Lines in ThePlane : N = 0 L0 = 1
  • 27.
    Lines in ThePlane : N = 1 L1 = 2
  • 28.
    Lines in ThePlane : N = 2 L2 = 4
  • 29.
    Lines in ThePlane : N = 3 L3 = 7
  • 30.
    Lines in ThePlane : N = 4 L4 = 11
  • 31.
    Lines in ThePlane : Maximum No. of Regions, Ln • for 0 line it creates 1 region; • for 1 lines, it creates 2 region; : Ln-1 + n = 1 + 1 = 2 • for 2 lines, it creates 4 region; : Ln-1 + n = 2 + 2 = 4 • for 3 lines, it will take 7 region: Ln-1 + n = 4 + 3 = 7 • for 4 lines, it will take 10 region: Ln-1 + n = 7 + 4 = 11 • for 5 lines... ? L0 = 1 Ln = Ln-1 + n, n>0
  • 32.
    Lines in ThePlane : Recursive Solution Difficulties L7 = ? L7 = L6 + 7 = L5 + 6 + 7 = L4 + 5+ 13 = L3 + 4 + 18 = L2 + 3 + 22 = L1 + 2 + 25 = L0 + 1 + 27 = 1+ 28 = 29 L50 = ? L50 = L49 + 50 = L48 + 49+ 50 = L47 + 48+ 99 = L46 + 47 +14 7 ………………………. =?
  • 33.
    Lines in ThePlane: Finding Closed Form Ln = Ln-1 + n = Ln-2 + (n-1) + n = Ln-3 + (n-2) + (n-1) + n = Ln-2 + (n-3) + (n-2) + (n-1) + n …………………….. = L0 + 1 + 2 + …… + (n-3) + (n-2) + (n-1) + n = 1 + 𝒏(𝒏+𝟏) 𝟐
  • 34.
    Lines in ThePlane : Proving Closed Form Basis : For n= 0, L0 = 1 + 𝟎(𝟎+𝟏) 𝟐 = 1 Induction : Let for n = n-1 the expression is true, then Ln-1 = 1 + 𝒏(𝒏 − 𝟏) 𝟐 Hypothesis : For n = n , Ln = Ln-1 + n = 1 + 𝒏(𝒏 − 𝟏) 𝟐 + n = 1 + 𝒏𝟐 − 𝒏 + 𝟐𝒏 𝟐 = 1 + 𝒏𝟐 + 𝒏 𝟐 = 1 + 𝒏(𝒏 + 𝟏) 𝟐
  • 35.
    Josephus Problem Do itYourself Solve Exercises
  • 36.