Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Recursive algorithm complexity part 1, Summaries of Algorithms and Programming

This document is a summary of the complexity of recursive algorithms. You can learn concisely about this subject.

Typology: Summaries

2018/2019

Available from 09/04/2021

PiotrRush
PiotrRush 🇮🇩

2 documents

1 / 5

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
RECURSIVE ALGORITHM COMPLEXITY
Part 1 : Homogeneous Linear Recurrence
Review : Time Complexity
T(n) copC(n)
Where :
T(n) : running time
n : input size
cop : execution time for basic operation
C(n) : number of times basic operation is executed
Counting the number of times the algorithm’s basic operation is executed on input of
size n.
There are several things to consider about recursive algorithm :
1. Recursive algorithm doesn’t use sum
2. The number of basic operations is difficult to identify how many times it is
executed
3. Find the recurrence relations
4. Solve the recurrence relation to get algorithm efficiency.
Example of recurrence relation
tn 3tn-1 4tn-2 = 0 for n > 1
t0 = 0
t1 = 1
tn 5tn-1 + 6tn-2 = 0 for n > 1
t0 = 0
t1 = 1
pf3
pf4
pf5

Partial preview of the text

Download Recursive algorithm complexity part 1 and more Summaries Algorithms and Programming in PDF only on Docsity!

RECURSIVE ALGORITHM COMPLEXITY

Part 1 : Homogeneous Linear Recurrence

Review : Time Complexity T(n)copC(n) Where : T(n) : running time n : input size cop : execution time for basic operation C(n) : number of times basic operation is executed Counting the number of times the algorithm’s basic operation is executed on input of size n. There are several things to consider about recursive algorithm :

  1. Recursive algorithm doesn’t use sum
  2. The number of basic operations is difficult to identify how many times it is executed
  3. Find the recurrence relations
  4. Solve the recurrence relation to get algorithm efficiency. Example of recurrence relation tn – 3tn- 1 – 4tn- 2 = 0 for n > 1 t 0 = 0 t 1 = 1 tn – 5tn- 1 + 6tn- 2 = 0 for n > 1 t 0 = 0 t 1 = 1

tn = tn- 1 + tn- 2 tn - tn- 1 + tn- 2 = 0

t 0 = 0 ⇒ t 0 = 0

t 1 = 1 t 1 = 1 Homogeneous Linear Recurrence The following are homogeneous linear recurrence equations with constant coefficients: 7tn – 3tn- 1 = 0 6tn – 5tn- 1 + 8tn- 2 = 0 8tn – 4tn- 3 = 0 a 0 tn + a 1 tn- 1 + … + aktn-k = 0

  • k and ai are constant
  • It’s called “ linear ” because every term ti appears only to the first power
  • It’s called “ homogeneous ” because the linear combination is equal to 0 The characteristic equation for the homogeneous linear recurrence equation with constant coefficients a 0 tn + a 1 tn- 1 + … + aktn-k = 0 is defined as a 0 rk^ + a 1 rk-^1 + … + akr^0 = 0 Example : The characteristic equation for the recurrence appears below it : 5tn + 7tn- 1 + 6tn- 2 = 0 5r^2 + 7r + 6 = 0 We use an arrow to show that the order of the characteristic equation is k (in this case is 2 )’

Theorem Let r be a root of multiplicity m of the characteristic equation for a homogeneous linear recurrence with constant coefficients. Then tn = rn, tn = nrn. tn = n^2 rn, tn = n^3 rn, …, tn = nm-^1 rn are all solution to the recurrence. To be continued in part 2

References Levitin’s book (Section 2.4) Neapolitan’s book (Appendix B)