12.07.2015 Views

A Practical Introduction to Data Structures and Algorithm Analysis

A Practical Introduction to Data Structures and Algorithm Analysis

A Practical Introduction to Data Structures and Algorithm Analysis

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

34 Chap. 2 Mathematical Preliminariesn∑i=0a i = an+1 − 1a − 1for a ≠ 1. (2.5)As special cases <strong>to</strong> Equation 2.5,n∑ 12 i = 1 − 12 n , (2.6)<strong>and</strong>i=1n∑2 i = 2 n+1 − 1. (2.7)i=0As a corollary <strong>to</strong> Equation 2.7,log∑n2 i = 2 log n+1 − 1 = 2n − 1. (2.8)Finally,i=0n∑i=1i2 i = 2 − n + 22 n . (2.9)The sum of reciprocals from 1 <strong>to</strong> n, called the Harmonic Series <strong>and</strong> writtenH n , has a value between log e n <strong>and</strong> log e n + 1. To be more precise, as n grows, thesummation grows closer <strong>to</strong>H n ≈ log e n + γ + 12n , (2.10)where γ is Euler’s constant <strong>and</strong> has the value 0.5772...Most of these equalities can be proved easily by mathematical induction (seeSection 2.6.3). Unfortunately, induction does not help us derive a closed-form solution.It only confirms when a proposed closed-form solution is correct. Techniquesfor deriving closed-form solutions are discussed in Section 14.1.The running time for a recursive algorithm is most easily expressed by a recursiveexpression because the <strong>to</strong>tal time for the recursive algorithm includes the time<strong>to</strong> run the recursive call(s). A recurrence relation defines a function by meansof an expression that includes one or more (smaller) instances of itself. A classicexample is the recursive definition for the fac<strong>to</strong>rial function:n! = (n − 1)! · n for n > 1; 1! = 0! = 1.Another st<strong>and</strong>ard example of a recurrence is the Fibonacci sequence:Fib(n) = Fib(n − 1) + Fib(n − 2) for n > 2; Fib(1) = Fib(2) = 1.

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

Saved successfully!

Ooh no, something went wrong!