06.03.2017 Views

Mathematics for Computer Science

e9ck2Ar

e9ck2Ar

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

“mcs” — 2017/3/3 — 11:21 — page 947 — #955<br />

22.3. Linear Recurrences 947<br />

is also a solution.<br />

All that remains is to select a solution consistent with the boundary conditions<br />

by choosing the constants appropriately. Each boundary condition implies a linear<br />

equation involving these constants. So we can determine the constants by solving<br />

a system of linear equations. For example, suppose our boundary conditions were<br />

f .0/ D 0, f .1/ D 1, f .2/ D 4 and f .3/ D 9. Then we would obtain four<br />

equations in four unknowns:<br />

f .0/ D 0 implies a s 0 C b t 0 C c u 0 C d 0u 0 D 0<br />

f .1/ D 1 implies a s 1 C b t 1 C c u 1 C d 1u 1 D 1<br />

f .2/ D 4 implies a s 2 C b t 2 C c u 2 C d 2u 2 D 4<br />

f .3/ D 9 implies a s 3 C b t 3 C c u 3 C d 3u 3 D 9<br />

This looks nasty, but remember that s, t and u are just constants. Solving this system<br />

gives values <strong>for</strong> a, b, c and d that define a solution to the recurrence consistent<br />

with the boundary conditions.<br />

22.3.3 Solving General Linear Recurrences<br />

We can now solve all linear homogeneous recurrences, which have the <strong>for</strong>m<br />

f .n/ D a 1 f .n 1/ C a 2 f .n 2/ C C a d f .n d/:<br />

Many recurrences that arise in practice do not quite fit this mold. For example, the<br />

Towers of Hanoi problem led to this recurrence:<br />

f .1/ D 1<br />

f .n/ D 2f .n 1/ C 1 (<strong>for</strong> n 2):<br />

The problem is the extra C1; that is not allowed in a homogeneous linear recurrence.<br />

In general, adding an extra function g.n/ to the right side of a linear recurrence<br />

gives an inhomogeneous linear recurrence:<br />

f .n/ D a 1 f .n 1/ C a 2 f .n 2/ C C a d f .n d/ C g.n/:<br />

Solving inhomogeneous linear recurrences is neither very different nor very difficult.<br />

We can divide the whole job into five steps:<br />

1. Replace g.n/ by 0, leaving a homogeneous recurrence. As be<strong>for</strong>e, find roots<br />

of the characteristic equation.<br />

2. Write down the solution to the homogeneous recurrence, but do not yet use<br />

the boundary conditions to determine coefficients. This is called the homogeneous<br />

solution.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!