2. 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.
3. 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.
4. 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 (+ – × ÷).
5. 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
7. 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.
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
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
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 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?
25. Lines in The Plane : Recursive Solution
Draw lines so that they intersect each others
Calculate maximum number of regions created by lines
31. 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