SlideShare une entreprise Scribd logo
1  sur  6
RECURRENCE EQUATION BY TARUN GEHLOTS

We solve recurrence equations often in analyzing
complexity of algorithms, circuits, and such other
cases.

A homogeneous recurrence equation is written as:
a0tn + a1tn-1 + . . . . + aktn-k = 0.

Solution technique:

Step 1: Set up a corresponding Characteristic
Equation:
a0 xn + a1 x(n-1) + …. + ak x(n-k) = 0,
x(n-k) [a0 xk + a1 x(k-1) + … +ak ] = 0,

a0xk + a1xk-1 + . . . . + ak = 0 [ for x =/= 0]

Step 2: Solve the characteristic equation as a
polynomial equation. Say, the real roots are r1, r2, . . . . ,
rk. Note, there are k solutions for k-th order
polynomial equation.
Step 3: The general solution for the original
recurrence equation is:
tn = i=1kcirin

Step 4: Using initial conditions (if available) solve
for the coefficients in above equation in order to find
the particular solution.

Example 1:
tn – 3tn-1 – 4tn-2 = 0, for n >= 2. {Initial condition:
t0=0, t1=1}

Characteristic equation: xn – 3x(n-1) – 4x(n-2) = 0,
Or, x(n-2) [x2 –3x –4] = 0,
Or, x2 – 3x – 4 = 0,
Or, x2 + x – 4x – 4 = 0,
Or, x(x+1) –4(x+1) = 0,
Or, (x+1)(x-4) = 0,
Therefore, roots are, x = -1, 4.

So, the general solution of the given recurrence
equation is:
tn = c1*(-1)n + c2*(4n)

Use t0 = c1 + c2 = 0, and t1 = -c1 + 4c2 = 1. [Note,
we need two initial conditions for two coefficients.]
Sove for c1 and c2,
c1 = -(1/5), c2 = (1/5).

So, the particular solution is:
tn = (1/5)[4n – (-1)n] = (4n)

End example.

Inhomogeneous recurrence equation

a0tn + a1tn-1 + . . . . + aktn-k = bnp(n), where b is a
          constant and p(n) is a polynomial of order n.

Solution technique:

Step 0: Homogenize the given equation to an
equivalent homogeneous recurrence equation form.

Step 1 through 3 (or 4) are the same as in the case of
solving homogeneous recurrence equation.

Example 2:

tn – 2tn-1 = 3n. [Note, this is a special case with p(n)
=1, polynomial of 0-th order, and there is no initial
condition – so we get the general solution only.]

Transform with n->n+1:
tn+1 – 2tn = 3n+1   Eqn(1).

Multiply original eqn with 3 on both the sides:
3tn – 6tn-1 = 3n+1 Eqn(2).

Subtract Eqn(2) from Eqn(1):
tn+1 – 5tn + 6tn-1 = 0, this is a homogeneous
recurrence equation which is equivalent to the given
inhomogeneous equation.

Characteristic equation: x2 – 5 x + 6 = 0.
Which is (x-2)(x-3) = 0.

So, roots are x = 2, 3.

General solution of the given recurrence equation is:
tn = c1*(2n) + c2*(3n) = (3n)

End example 2.

Homogenizing may need multiple steps.

Example 3:

tn – 2tn-1 = n

So, tn+1 – 2tn = n+1
Subtracting the former (given) eqn from the latter
eqn,
tn+1 – 3tn + 2tn-1 = 1

Still not a homogeneous eqn. Second stage of
homogenizing,
tn+2 – 3tn+1 + 2tn = 1

Subtract once again,
tn+2 – 4tn+1 + 5tn - 2tn-1 = 0

Now it is a homogeneous recurrence equation and
one can solve it in the usual way.

End example 3e.

An important special case:

If the characteristic eqn. is like
(x-2)(x-3)2 = 0,      [CAN YOU CONSTRUCT THE
ORIGINAL HOMOGENEOUS RECURRENCE EQN
BACK?]

The roots are x = 2, 3, 3 for a polynomial eqn. of
order 3.

The general solution for the given recurrence eqn. is
then,
tn = c1*(2n) + c2*(3n) + c3*n*(3n)

Note the additional n in the third term.

If the roots were
x = 3, 3, 3, then

The general solution would be
tn = c1*(3n) + c2*n*(3n) + c3*(n2)*( 3n),

and so on so forth…


A special type of recurrence equation that is
frequently encountered in algorithms' analyses
                    i
T(n) = aT(n/b) + cn , for some constant integer i, and
constants of coefficients a and c.

Three cases:
     i
a = b , the solution is T(n) = O(ni log b n);
     i                                  a
a > b , the solution is T(n) = O(nlog_b );
     i
a < b , the solution is T(n) = O(ni);

Contenu connexe

Tendances

0/1 DYNAMIC PROGRAMMING KNAPSACK PROBLEM
0/1 DYNAMIC PROGRAMMING KNAPSACK PROBLEM0/1 DYNAMIC PROGRAMMING KNAPSACK PROBLEM
0/1 DYNAMIC PROGRAMMING KNAPSACK PROBLEM
Mrunal Patil
 
Dynamic programming, Branch and bound algorithm & Greedy algorithms
Dynamic programming, Branch and bound algorithm & Greedy algorithms Dynamic programming, Branch and bound algorithm & Greedy algorithms
Dynamic programming, Branch and bound algorithm & Greedy algorithms
SURBHI SAROHA
 

Tendances (20)

Presentation of daa on approximation algorithm and vertex cover problem
Presentation of daa on approximation algorithm and vertex cover problem Presentation of daa on approximation algorithm and vertex cover problem
Presentation of daa on approximation algorithm and vertex cover problem
 
0/1 DYNAMIC PROGRAMMING KNAPSACK PROBLEM
0/1 DYNAMIC PROGRAMMING KNAPSACK PROBLEM0/1 DYNAMIC PROGRAMMING KNAPSACK PROBLEM
0/1 DYNAMIC PROGRAMMING KNAPSACK PROBLEM
 
Sum of subsets problem by backtracking 
Sum of subsets problem by backtracking Sum of subsets problem by backtracking 
Sum of subsets problem by backtracking 
 
Algorithms Lecture 3: Analysis of Algorithms II
Algorithms Lecture 3: Analysis of Algorithms IIAlgorithms Lecture 3: Analysis of Algorithms II
Algorithms Lecture 3: Analysis of Algorithms II
 
Dynamic programming
Dynamic programmingDynamic programming
Dynamic programming
 
Divide and Conquer - Part 1
Divide and Conquer - Part 1Divide and Conquer - Part 1
Divide and Conquer - Part 1
 
Lecture: Automata
Lecture: AutomataLecture: Automata
Lecture: Automata
 
L3 cfg
L3 cfgL3 cfg
L3 cfg
 
Maximum Matching in General Graphs
Maximum Matching in General GraphsMaximum Matching in General Graphs
Maximum Matching in General Graphs
 
Network flows
Network flowsNetwork flows
Network flows
 
TOC 7 | CFG in Chomsky Normal Form
TOC 7 | CFG in Chomsky Normal FormTOC 7 | CFG in Chomsky Normal Form
TOC 7 | CFG in Chomsky Normal Form
 
Algorithms - "Chapter 2 getting started"
Algorithms - "Chapter 2 getting started"Algorithms - "Chapter 2 getting started"
Algorithms - "Chapter 2 getting started"
 
Regular Grammar
Regular GrammarRegular Grammar
Regular Grammar
 
Graph algorithms
Graph algorithmsGraph algorithms
Graph algorithms
 
Graphs in Data Structure
 Graphs in Data Structure Graphs in Data Structure
Graphs in Data Structure
 
Greedy Algorithm
Greedy AlgorithmGreedy Algorithm
Greedy Algorithm
 
Dynamic programming, Branch and bound algorithm & Greedy algorithms
Dynamic programming, Branch and bound algorithm & Greedy algorithms Dynamic programming, Branch and bound algorithm & Greedy algorithms
Dynamic programming, Branch and bound algorithm & Greedy algorithms
 
simple problem to convert NFA with epsilon to without epsilon
simple problem to convert NFA with epsilon to without epsilonsimple problem to convert NFA with epsilon to without epsilon
simple problem to convert NFA with epsilon to without epsilon
 
Graph theory
Graph theoryGraph theory
Graph theory
 
Branch and bound
Branch and boundBranch and bound
Branch and bound
 

En vedette

Real meaning of functions
Real meaning of functionsReal meaning of functions
Real meaning of functions
Tarun Gehlot
 
How to draw a good graph
How to draw a good graphHow to draw a good graph
How to draw a good graph
Tarun Gehlot
 
An applied approach to calculas
An applied approach to calculasAn applied approach to calculas
An applied approach to calculas
Tarun Gehlot
 
Graphs of trigonometric functions
Graphs of trigonometric functionsGraphs of trigonometric functions
Graphs of trigonometric functions
Tarun Gehlot
 
Solution of nonlinear_equations
Solution of nonlinear_equationsSolution of nonlinear_equations
Solution of nonlinear_equations
Tarun Gehlot
 
Probability and statistics as helpers in real life
Probability and statistics as helpers in real lifeProbability and statistics as helpers in real life
Probability and statistics as helpers in real life
Tarun Gehlot
 
C4 discontinuities
C4 discontinuitiesC4 discontinuities
C4 discontinuities
Tarun Gehlot
 
The shortest distance between skew lines
The shortest distance between skew linesThe shortest distance between skew lines
The shortest distance between skew lines
Tarun Gehlot
 
Linear programming
Linear programmingLinear programming
Linear programming
Tarun Gehlot
 
Limitations of linear programming
Limitations of linear programmingLimitations of linear programming
Limitations of linear programming
Tarun Gehlot
 

En vedette (20)

Logicgates
LogicgatesLogicgates
Logicgates
 
Intervals of validity
Intervals of validityIntervals of validity
Intervals of validity
 
Modelling with first order differential equations
Modelling with first order differential equationsModelling with first order differential equations
Modelling with first order differential equations
 
Real meaning of functions
Real meaning of functionsReal meaning of functions
Real meaning of functions
 
How to draw a good graph
How to draw a good graphHow to draw a good graph
How to draw a good graph
 
Describing and exploring data
Describing and exploring dataDescribing and exploring data
Describing and exploring data
 
Linear approximations
Linear approximationsLinear approximations
Linear approximations
 
Critical points
Critical pointsCritical points
Critical points
 
An applied approach to calculas
An applied approach to calculasAn applied approach to calculas
An applied approach to calculas
 
Graphs of trigonometric functions
Graphs of trigonometric functionsGraphs of trigonometric functions
Graphs of trigonometric functions
 
Solution of nonlinear_equations
Solution of nonlinear_equationsSolution of nonlinear_equations
Solution of nonlinear_equations
 
Matrix algebra
Matrix algebraMatrix algebra
Matrix algebra
 
Probability and statistics as helpers in real life
Probability and statistics as helpers in real lifeProbability and statistics as helpers in real life
Probability and statistics as helpers in real life
 
C4 discontinuities
C4 discontinuitiesC4 discontinuities
C4 discontinuities
 
The shortest distance between skew lines
The shortest distance between skew linesThe shortest distance between skew lines
The shortest distance between skew lines
 
Thermo dynamics
Thermo dynamicsThermo dynamics
Thermo dynamics
 
Review taylor series
Review taylor seriesReview taylor series
Review taylor series
 
The newton raphson method
The newton raphson methodThe newton raphson method
The newton raphson method
 
Linear programming
Linear programmingLinear programming
Linear programming
 
Limitations of linear programming
Limitations of linear programmingLimitations of linear programming
Limitations of linear programming
 

Similaire à Recurrence equations

Analysis Of Algorithms Ii
Analysis Of Algorithms IiAnalysis Of Algorithms Ii
Analysis Of Algorithms Ii
Sri Prasanna
 
8.-DAA-LECTURE-8-RECURRENCES-AND-ITERATION-METHOD.pdf
8.-DAA-LECTURE-8-RECURRENCES-AND-ITERATION-METHOD.pdf8.-DAA-LECTURE-8-RECURRENCES-AND-ITERATION-METHOD.pdf
8.-DAA-LECTURE-8-RECURRENCES-AND-ITERATION-METHOD.pdf
RishikeshJha33
 
T2311 - Ch 4_Part1.pptx
T2311 - Ch 4_Part1.pptxT2311 - Ch 4_Part1.pptx
T2311 - Ch 4_Part1.pptx
GadaFarhan
 

Similaire à Recurrence equations (20)

Daa linear recurrences
Daa linear recurrencesDaa linear recurrences
Daa linear recurrences
 
LINEAR RECURRENCE RELATIONS WITH CONSTANT COEFFICIENTS
 LINEAR RECURRENCE RELATIONS WITH CONSTANT COEFFICIENTS LINEAR RECURRENCE RELATIONS WITH CONSTANT COEFFICIENTS
LINEAR RECURRENCE RELATIONS WITH CONSTANT COEFFICIENTS
 
recurence solutions
recurence solutionsrecurence solutions
recurence solutions
 
Solving linear homogeneous recurrence relations
Solving linear homogeneous recurrence relationsSolving linear homogeneous recurrence relations
Solving linear homogeneous recurrence relations
 
Time complexity
Time complexityTime complexity
Time complexity
 
Solving recurrences
Solving recurrencesSolving recurrences
Solving recurrences
 
Solving recurrences
Solving recurrencesSolving recurrences
Solving recurrences
 
3.pdf
3.pdf3.pdf
3.pdf
 
Ch07 7
Ch07 7Ch07 7
Ch07 7
 
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
 
Analysis Of Algorithms Ii
Analysis Of Algorithms IiAnalysis Of Algorithms Ii
Analysis Of Algorithms Ii
 
Ch07 5
Ch07 5Ch07 5
Ch07 5
 
RECURRENCE EQUATIONS & ANALYZING THEM
RECURRENCE EQUATIONS & ANALYZING THEMRECURRENCE EQUATIONS & ANALYZING THEM
RECURRENCE EQUATIONS & ANALYZING THEM
 
Recurrence_Theory.pptx studdents nees free
Recurrence_Theory.pptx studdents nees freeRecurrence_Theory.pptx studdents nees free
Recurrence_Theory.pptx studdents nees free
 
Ch07 6
Ch07 6Ch07 6
Ch07 6
 
Maths
MathsMaths
Maths
 
8.-DAA-LECTURE-8-RECURRENCES-AND-ITERATION-METHOD.pdf
8.-DAA-LECTURE-8-RECURRENCES-AND-ITERATION-METHOD.pdf8.-DAA-LECTURE-8-RECURRENCES-AND-ITERATION-METHOD.pdf
8.-DAA-LECTURE-8-RECURRENCES-AND-ITERATION-METHOD.pdf
 
T2311 - Ch 4_Part1.pptx
T2311 - Ch 4_Part1.pptxT2311 - Ch 4_Part1.pptx
T2311 - Ch 4_Part1.pptx
 
Impact of Linear Homogeneous Recurrent Relation Analysis
Impact of Linear Homogeneous Recurrent Relation AnalysisImpact of Linear Homogeneous Recurrent Relation Analysis
Impact of Linear Homogeneous Recurrent Relation Analysis
 
Recurrence Relation
Recurrence RelationRecurrence Relation
Recurrence Relation
 

Plus de Tarun Gehlot

Plus de Tarun Gehlot (20)

Materials 11-01228
Materials 11-01228Materials 11-01228
Materials 11-01228
 
Binary relations
Binary relationsBinary relations
Binary relations
 
Continuity and end_behavior
Continuity and  end_behaviorContinuity and  end_behavior
Continuity and end_behavior
 
Continuity of functions by graph (exercises with detailed solutions)
Continuity of functions by graph   (exercises with detailed solutions)Continuity of functions by graph   (exercises with detailed solutions)
Continuity of functions by graph (exercises with detailed solutions)
 
Factoring by the trial and-error method
Factoring by the trial and-error methodFactoring by the trial and-error method
Factoring by the trial and-error method
 
Introduction to finite element analysis
Introduction to finite element analysisIntroduction to finite element analysis
Introduction to finite element analysis
 
Finite elements : basis functions
Finite elements : basis functionsFinite elements : basis functions
Finite elements : basis functions
 
Finite elements for 2‐d problems
Finite elements  for 2‐d problemsFinite elements  for 2‐d problems
Finite elements for 2‐d problems
 
Error analysis statistics
Error analysis   statisticsError analysis   statistics
Error analysis statistics
 
Matlab commands
Matlab commandsMatlab commands
Matlab commands
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
 
Linear approximations and_differentials
Linear approximations and_differentialsLinear approximations and_differentials
Linear approximations and_differentials
 
Local linear approximation
Local linear approximationLocal linear approximation
Local linear approximation
 
Interpolation functions
Interpolation functionsInterpolation functions
Interpolation functions
 
Propeties of-triangles
Propeties of-trianglesPropeties of-triangles
Propeties of-triangles
 
Gaussian quadratures
Gaussian quadraturesGaussian quadratures
Gaussian quadratures
 
Basics of set theory
Basics of set theoryBasics of set theory
Basics of set theory
 
Numerical integration
Numerical integrationNumerical integration
Numerical integration
 
Applications of set theory
Applications of  set theoryApplications of  set theory
Applications of set theory
 
Miscellneous functions
Miscellneous  functionsMiscellneous  functions
Miscellneous functions
 

Recurrence equations

  • 1. RECURRENCE EQUATION BY TARUN GEHLOTS We solve recurrence equations often in analyzing complexity of algorithms, circuits, and such other cases. A homogeneous recurrence equation is written as: a0tn + a1tn-1 + . . . . + aktn-k = 0. Solution technique: Step 1: Set up a corresponding Characteristic Equation: a0 xn + a1 x(n-1) + …. + ak x(n-k) = 0, x(n-k) [a0 xk + a1 x(k-1) + … +ak ] = 0, a0xk + a1xk-1 + . . . . + ak = 0 [ for x =/= 0] Step 2: Solve the characteristic equation as a polynomial equation. Say, the real roots are r1, r2, . . . . , rk. Note, there are k solutions for k-th order polynomial equation.
  • 2. Step 3: The general solution for the original recurrence equation is: tn = i=1kcirin Step 4: Using initial conditions (if available) solve for the coefficients in above equation in order to find the particular solution. Example 1: tn – 3tn-1 – 4tn-2 = 0, for n >= 2. {Initial condition: t0=0, t1=1} Characteristic equation: xn – 3x(n-1) – 4x(n-2) = 0, Or, x(n-2) [x2 –3x –4] = 0, Or, x2 – 3x – 4 = 0, Or, x2 + x – 4x – 4 = 0, Or, x(x+1) –4(x+1) = 0, Or, (x+1)(x-4) = 0, Therefore, roots are, x = -1, 4. So, the general solution of the given recurrence equation is: tn = c1*(-1)n + c2*(4n) Use t0 = c1 + c2 = 0, and t1 = -c1 + 4c2 = 1. [Note, we need two initial conditions for two coefficients.]
  • 3. Sove for c1 and c2, c1 = -(1/5), c2 = (1/5). So, the particular solution is: tn = (1/5)[4n – (-1)n] = (4n) End example. Inhomogeneous recurrence equation a0tn + a1tn-1 + . . . . + aktn-k = bnp(n), where b is a constant and p(n) is a polynomial of order n. Solution technique: Step 0: Homogenize the given equation to an equivalent homogeneous recurrence equation form. Step 1 through 3 (or 4) are the same as in the case of solving homogeneous recurrence equation. Example 2: tn – 2tn-1 = 3n. [Note, this is a special case with p(n) =1, polynomial of 0-th order, and there is no initial condition – so we get the general solution only.] Transform with n->n+1:
  • 4. tn+1 – 2tn = 3n+1 Eqn(1). Multiply original eqn with 3 on both the sides: 3tn – 6tn-1 = 3n+1 Eqn(2). Subtract Eqn(2) from Eqn(1): tn+1 – 5tn + 6tn-1 = 0, this is a homogeneous recurrence equation which is equivalent to the given inhomogeneous equation. Characteristic equation: x2 – 5 x + 6 = 0. Which is (x-2)(x-3) = 0. So, roots are x = 2, 3. General solution of the given recurrence equation is: tn = c1*(2n) + c2*(3n) = (3n) End example 2. Homogenizing may need multiple steps. Example 3: tn – 2tn-1 = n So, tn+1 – 2tn = n+1
  • 5. Subtracting the former (given) eqn from the latter eqn, tn+1 – 3tn + 2tn-1 = 1 Still not a homogeneous eqn. Second stage of homogenizing, tn+2 – 3tn+1 + 2tn = 1 Subtract once again, tn+2 – 4tn+1 + 5tn - 2tn-1 = 0 Now it is a homogeneous recurrence equation and one can solve it in the usual way. End example 3e. An important special case: If the characteristic eqn. is like (x-2)(x-3)2 = 0, [CAN YOU CONSTRUCT THE ORIGINAL HOMOGENEOUS RECURRENCE EQN BACK?] The roots are x = 2, 3, 3 for a polynomial eqn. of order 3. The general solution for the given recurrence eqn. is then,
  • 6. tn = c1*(2n) + c2*(3n) + c3*n*(3n) Note the additional n in the third term. If the roots were x = 3, 3, 3, then The general solution would be tn = c1*(3n) + c2*n*(3n) + c3*(n2)*( 3n), and so on so forth… A special type of recurrence equation that is frequently encountered in algorithms' analyses i T(n) = aT(n/b) + cn , for some constant integer i, and constants of coefficients a and c. Three cases: i a = b , the solution is T(n) = O(ni log b n); i a a > b , the solution is T(n) = O(nlog_b ); i a < b , the solution is T(n) = O(ni);