Recurrence Relations - West Virginia...

127
Outline Recurrence Relations K. Subramani 1 1 Lane Department of Computer Science and Electrical Engineering West Virginia University 18 January, 2011 Subramani Recursion

Transcript of Recurrence Relations - West Virginia...

Page 1: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

Outline

Recurrence Relations

K. Subramani1

1Lane Department of Computer Science and Electrical EngineeringWest Virginia University

18 January, 2011

Subramani Recursion

Page 2: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

Outline

Outline

1 Recurrences

2 Solving Recurrences

Subramani Recursion

Page 3: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

Outline

Outline

1 Recurrences

2 Solving Recurrences

Subramani Recursion

Page 4: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

Sample Recurrences

Examples

(i)

S(1) = 2

S(n) = 2 · S(n − 1), n ≥ 2.

(ii)

T (1) = 1

T (n) = T (n − 1) + 3, n ≥ 2.

(iii)

F (1) = 1

F (2) = 1

F (n) = F (n − 1) + F (n − 2), n ≥ 3

Subramani Recursion

Page 5: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

Sample Recurrences

Examples

(i)

S(1) = 2

S(n) = 2 · S(n − 1), n ≥ 2.

(ii)

T (1) = 1

T (n) = T (n − 1) + 3, n ≥ 2.

(iii)

F (1) = 1

F (2) = 1

F (n) = F (n − 1) + F (n − 2), n ≥ 3

Subramani Recursion

Page 6: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

Sample Recurrences

Examples

(i)

S(1) = 2

S(n) = 2 · S(n − 1), n ≥ 2.

(ii)

T (1) = 1

T (n) = T (n − 1) + 3, n ≥ 2.

(iii)

F (1) = 1

F (2) = 1

F (n) = F (n − 1) + F (n − 2), n ≥ 3

Subramani Recursion

Page 7: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

Sample Recurrences

Examples

(i)

S(1) = 2

S(n) = 2 · S(n − 1), n ≥ 2.

(ii)

T (1) = 1

T (n) = T (n − 1) + 3, n ≥ 2.

(iii)

F (1) = 1

F (2) = 1

F (n) = F (n − 1) + F (n − 2), n ≥ 3

Subramani Recursion

Page 8: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

Solving recurrences

Three methods

(i) Expand-Guess-Verify (EGV).

(ii) Formula.

(iii) Recursion Tree.

Subramani Recursion

Page 9: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

Solving recurrences

Three methods

(i) Expand-Guess-Verify (EGV).

(ii) Formula.

(iii) Recursion Tree.

Subramani Recursion

Page 10: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

Solving recurrences

Three methods

(i) Expand-Guess-Verify (EGV).

(ii) Formula.

(iii) Recursion Tree.

Subramani Recursion

Page 11: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

Solving recurrences

Three methods

(i) Expand-Guess-Verify (EGV).

(ii) Formula.

(iii) Recursion Tree.

Subramani Recursion

Page 12: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

EGV

ExampleConsider the recurrence:

S(1) = 2

S(n) = 2 · S(n − 1), n ≥ 2.

(i) Expand: S(1) = 2, S(2) = 2 · 2 = 4, S(3) = 2 · S(2) = 8, . . . .

(ii) Guess: S(n) = 2n

(iii) Verify: Using Induction!BASIS: n = 1

LHS = 2

RHS = 21

= 2

Since LHS=RHS, the basis is proven.INDUCTIVE STEP: Assume that S(k) = 2k . We need to show that S(k + 1) = 2k+1. Observe that,

S(k + 1) = 2 · S(k), by definition

= 2 · 2k, by inductive hypothesis

= 2k+1!

Applying the first principle of mathematical induction, we conclude that S(n) = 2n .

Subramani Recursion

Page 13: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

EGV

ExampleConsider the recurrence:

S(1) = 2

S(n) = 2 · S(n − 1), n ≥ 2.

(i) Expand: S(1) = 2,

S(2) = 2 · 2 = 4, S(3) = 2 · S(2) = 8, . . . .

(ii) Guess: S(n) = 2n

(iii) Verify: Using Induction!BASIS: n = 1

LHS = 2

RHS = 21

= 2

Since LHS=RHS, the basis is proven.INDUCTIVE STEP: Assume that S(k) = 2k . We need to show that S(k + 1) = 2k+1. Observe that,

S(k + 1) = 2 · S(k), by definition

= 2 · 2k, by inductive hypothesis

= 2k+1!

Applying the first principle of mathematical induction, we conclude that S(n) = 2n .

Subramani Recursion

Page 14: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

EGV

ExampleConsider the recurrence:

S(1) = 2

S(n) = 2 · S(n − 1), n ≥ 2.

(i) Expand: S(1) = 2, S(2) = 2 · 2 = 4,

S(3) = 2 · S(2) = 8, . . . .

(ii) Guess: S(n) = 2n

(iii) Verify: Using Induction!BASIS: n = 1

LHS = 2

RHS = 21

= 2

Since LHS=RHS, the basis is proven.INDUCTIVE STEP: Assume that S(k) = 2k . We need to show that S(k + 1) = 2k+1. Observe that,

S(k + 1) = 2 · S(k), by definition

= 2 · 2k, by inductive hypothesis

= 2k+1!

Applying the first principle of mathematical induction, we conclude that S(n) = 2n .

Subramani Recursion

Page 15: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

EGV

ExampleConsider the recurrence:

S(1) = 2

S(n) = 2 · S(n − 1), n ≥ 2.

(i) Expand: S(1) = 2, S(2) = 2 · 2 = 4, S(3) = 2 · S(2) = 8,

. . . .

(ii) Guess: S(n) = 2n

(iii) Verify: Using Induction!BASIS: n = 1

LHS = 2

RHS = 21

= 2

Since LHS=RHS, the basis is proven.INDUCTIVE STEP: Assume that S(k) = 2k . We need to show that S(k + 1) = 2k+1. Observe that,

S(k + 1) = 2 · S(k), by definition

= 2 · 2k, by inductive hypothesis

= 2k+1!

Applying the first principle of mathematical induction, we conclude that S(n) = 2n .

Subramani Recursion

Page 16: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

EGV

ExampleConsider the recurrence:

S(1) = 2

S(n) = 2 · S(n − 1), n ≥ 2.

(i) Expand: S(1) = 2, S(2) = 2 · 2 = 4, S(3) = 2 · S(2) = 8, . . . .

(ii) Guess: S(n) = 2n

(iii) Verify: Using Induction!BASIS: n = 1

LHS = 2

RHS = 21

= 2

Since LHS=RHS, the basis is proven.INDUCTIVE STEP: Assume that S(k) = 2k . We need to show that S(k + 1) = 2k+1. Observe that,

S(k + 1) = 2 · S(k), by definition

= 2 · 2k, by inductive hypothesis

= 2k+1!

Applying the first principle of mathematical induction, we conclude that S(n) = 2n .

Subramani Recursion

Page 17: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

EGV

ExampleConsider the recurrence:

S(1) = 2

S(n) = 2 · S(n − 1), n ≥ 2.

(i) Expand: S(1) = 2, S(2) = 2 · 2 = 4, S(3) = 2 · S(2) = 8, . . . .

(ii) Guess: S(n) = 2n

(iii) Verify: Using Induction!BASIS: n = 1

LHS = 2

RHS = 21

= 2

Since LHS=RHS, the basis is proven.INDUCTIVE STEP: Assume that S(k) = 2k . We need to show that S(k + 1) = 2k+1. Observe that,

S(k + 1) = 2 · S(k), by definition

= 2 · 2k, by inductive hypothesis

= 2k+1!

Applying the first principle of mathematical induction, we conclude that S(n) = 2n .

Subramani Recursion

Page 18: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

EGV

ExampleConsider the recurrence:

S(1) = 2

S(n) = 2 · S(n − 1), n ≥ 2.

(i) Expand: S(1) = 2, S(2) = 2 · 2 = 4, S(3) = 2 · S(2) = 8, . . . .

(ii) Guess: S(n) = 2n

(iii) Verify:

Using Induction!BASIS: n = 1

LHS = 2

RHS = 21

= 2

Since LHS=RHS, the basis is proven.INDUCTIVE STEP: Assume that S(k) = 2k . We need to show that S(k + 1) = 2k+1. Observe that,

S(k + 1) = 2 · S(k), by definition

= 2 · 2k, by inductive hypothesis

= 2k+1!

Applying the first principle of mathematical induction, we conclude that S(n) = 2n .

Subramani Recursion

Page 19: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

EGV

ExampleConsider the recurrence:

S(1) = 2

S(n) = 2 · S(n − 1), n ≥ 2.

(i) Expand: S(1) = 2, S(2) = 2 · 2 = 4, S(3) = 2 · S(2) = 8, . . . .

(ii) Guess: S(n) = 2n

(iii) Verify: Using Induction!

BASIS: n = 1

LHS = 2

RHS = 21

= 2

Since LHS=RHS, the basis is proven.INDUCTIVE STEP: Assume that S(k) = 2k . We need to show that S(k + 1) = 2k+1. Observe that,

S(k + 1) = 2 · S(k), by definition

= 2 · 2k, by inductive hypothesis

= 2k+1!

Applying the first principle of mathematical induction, we conclude that S(n) = 2n .

Subramani Recursion

Page 20: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

EGV

ExampleConsider the recurrence:

S(1) = 2

S(n) = 2 · S(n − 1), n ≥ 2.

(i) Expand: S(1) = 2, S(2) = 2 · 2 = 4, S(3) = 2 · S(2) = 8, . . . .

(ii) Guess: S(n) = 2n

(iii) Verify: Using Induction!BASIS: n = 1

LHS = 2

RHS = 21

= 2

Since LHS=RHS, the basis is proven.INDUCTIVE STEP: Assume that S(k) = 2k . We need to show that S(k + 1) = 2k+1. Observe that,

S(k + 1) = 2 · S(k), by definition

= 2 · 2k, by inductive hypothesis

= 2k+1!

Applying the first principle of mathematical induction, we conclude that S(n) = 2n .

Subramani Recursion

Page 21: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

EGV

ExampleConsider the recurrence:

S(1) = 2

S(n) = 2 · S(n − 1), n ≥ 2.

(i) Expand: S(1) = 2, S(2) = 2 · 2 = 4, S(3) = 2 · S(2) = 8, . . . .

(ii) Guess: S(n) = 2n

(iii) Verify: Using Induction!BASIS: n = 1

LHS = 2

RHS = 21

= 2

Since LHS=RHS, the basis is proven.INDUCTIVE STEP: Assume that S(k) = 2k . We need to show that S(k + 1) = 2k+1. Observe that,

S(k + 1) = 2 · S(k), by definition

= 2 · 2k, by inductive hypothesis

= 2k+1!

Applying the first principle of mathematical induction, we conclude that S(n) = 2n .

Subramani Recursion

Page 22: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

EGV

ExampleConsider the recurrence:

S(1) = 2

S(n) = 2 · S(n − 1), n ≥ 2.

(i) Expand: S(1) = 2, S(2) = 2 · 2 = 4, S(3) = 2 · S(2) = 8, . . . .

(ii) Guess: S(n) = 2n

(iii) Verify: Using Induction!BASIS: n = 1

LHS = 2

RHS = 21

= 2

Since LHS=RHS, the basis is proven.INDUCTIVE STEP: Assume that S(k) = 2k . We need to show that S(k + 1) = 2k+1. Observe that,

S(k + 1) = 2 · S(k), by definition

= 2 · 2k, by inductive hypothesis

= 2k+1!

Applying the first principle of mathematical induction, we conclude that S(n) = 2n .

Subramani Recursion

Page 23: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

EGV

ExampleConsider the recurrence:

S(1) = 2

S(n) = 2 · S(n − 1), n ≥ 2.

(i) Expand: S(1) = 2, S(2) = 2 · 2 = 4, S(3) = 2 · S(2) = 8, . . . .

(ii) Guess: S(n) = 2n

(iii) Verify: Using Induction!BASIS: n = 1

LHS = 2

RHS = 21

= 2

Since LHS=RHS, the basis is proven.INDUCTIVE STEP: Assume that S(k) = 2k . We need to show that S(k + 1) = 2k+1. Observe that,

S(k + 1) = 2 · S(k), by definition

= 2 · 2k, by inductive hypothesis

= 2k+1!

Applying the first principle of mathematical induction, we conclude that S(n) = 2n .

Subramani Recursion

Page 24: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

EGV

ExampleConsider the recurrence:

S(1) = 2

S(n) = 2 · S(n − 1), n ≥ 2.

(i) Expand: S(1) = 2, S(2) = 2 · 2 = 4, S(3) = 2 · S(2) = 8, . . . .

(ii) Guess: S(n) = 2n

(iii) Verify: Using Induction!BASIS: n = 1

LHS = 2

RHS = 21

= 2

Since LHS=RHS, the basis is proven.

INDUCTIVE STEP: Assume that S(k) = 2k . We need to show that S(k + 1) = 2k+1. Observe that,

S(k + 1) = 2 · S(k), by definition

= 2 · 2k, by inductive hypothesis

= 2k+1!

Applying the first principle of mathematical induction, we conclude that S(n) = 2n .

Subramani Recursion

Page 25: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

EGV

ExampleConsider the recurrence:

S(1) = 2

S(n) = 2 · S(n − 1), n ≥ 2.

(i) Expand: S(1) = 2, S(2) = 2 · 2 = 4, S(3) = 2 · S(2) = 8, . . . .

(ii) Guess: S(n) = 2n

(iii) Verify: Using Induction!BASIS: n = 1

LHS = 2

RHS = 21

= 2

Since LHS=RHS, the basis is proven.INDUCTIVE STEP: Assume that S(k) = 2k .

We need to show that S(k + 1) = 2k+1. Observe that,

S(k + 1) = 2 · S(k), by definition

= 2 · 2k, by inductive hypothesis

= 2k+1!

Applying the first principle of mathematical induction, we conclude that S(n) = 2n .

Subramani Recursion

Page 26: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

EGV

ExampleConsider the recurrence:

S(1) = 2

S(n) = 2 · S(n − 1), n ≥ 2.

(i) Expand: S(1) = 2, S(2) = 2 · 2 = 4, S(3) = 2 · S(2) = 8, . . . .

(ii) Guess: S(n) = 2n

(iii) Verify: Using Induction!BASIS: n = 1

LHS = 2

RHS = 21

= 2

Since LHS=RHS, the basis is proven.INDUCTIVE STEP: Assume that S(k) = 2k . We need to show that S(k + 1) = 2k+1.

Observe that,

S(k + 1) = 2 · S(k), by definition

= 2 · 2k, by inductive hypothesis

= 2k+1!

Applying the first principle of mathematical induction, we conclude that S(n) = 2n .

Subramani Recursion

Page 27: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

EGV

ExampleConsider the recurrence:

S(1) = 2

S(n) = 2 · S(n − 1), n ≥ 2.

(i) Expand: S(1) = 2, S(2) = 2 · 2 = 4, S(3) = 2 · S(2) = 8, . . . .

(ii) Guess: S(n) = 2n

(iii) Verify: Using Induction!BASIS: n = 1

LHS = 2

RHS = 21

= 2

Since LHS=RHS, the basis is proven.INDUCTIVE STEP: Assume that S(k) = 2k . We need to show that S(k + 1) = 2k+1. Observe that,

S(k + 1) = 2 · S(k), by definition

= 2 · 2k, by inductive hypothesis

= 2k+1!

Applying the first principle of mathematical induction, we conclude that S(n) = 2n .

Subramani Recursion

Page 28: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

EGV

ExampleConsider the recurrence:

S(1) = 2

S(n) = 2 · S(n − 1), n ≥ 2.

(i) Expand: S(1) = 2, S(2) = 2 · 2 = 4, S(3) = 2 · S(2) = 8, . . . .

(ii) Guess: S(n) = 2n

(iii) Verify: Using Induction!BASIS: n = 1

LHS = 2

RHS = 21

= 2

Since LHS=RHS, the basis is proven.INDUCTIVE STEP: Assume that S(k) = 2k . We need to show that S(k + 1) = 2k+1. Observe that,

S(k + 1) =

2 · S(k), by definition

= 2 · 2k, by inductive hypothesis

= 2k+1!

Applying the first principle of mathematical induction, we conclude that S(n) = 2n .

Subramani Recursion

Page 29: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

EGV

ExampleConsider the recurrence:

S(1) = 2

S(n) = 2 · S(n − 1), n ≥ 2.

(i) Expand: S(1) = 2, S(2) = 2 · 2 = 4, S(3) = 2 · S(2) = 8, . . . .

(ii) Guess: S(n) = 2n

(iii) Verify: Using Induction!BASIS: n = 1

LHS = 2

RHS = 21

= 2

Since LHS=RHS, the basis is proven.INDUCTIVE STEP: Assume that S(k) = 2k . We need to show that S(k + 1) = 2k+1. Observe that,

S(k + 1) = 2 · S(k), by definition

= 2 · 2k, by inductive hypothesis

= 2k+1!

Applying the first principle of mathematical induction, we conclude that S(n) = 2n .

Subramani Recursion

Page 30: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

EGV

ExampleConsider the recurrence:

S(1) = 2

S(n) = 2 · S(n − 1), n ≥ 2.

(i) Expand: S(1) = 2, S(2) = 2 · 2 = 4, S(3) = 2 · S(2) = 8, . . . .

(ii) Guess: S(n) = 2n

(iii) Verify: Using Induction!BASIS: n = 1

LHS = 2

RHS = 21

= 2

Since LHS=RHS, the basis is proven.INDUCTIVE STEP: Assume that S(k) = 2k . We need to show that S(k + 1) = 2k+1. Observe that,

S(k + 1) = 2 · S(k), by definition

= 2 · 2k, by inductive hypothesis

= 2k+1!

Applying the first principle of mathematical induction, we conclude that S(n) = 2n .

Subramani Recursion

Page 31: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

EGV

ExampleConsider the recurrence:

S(1) = 2

S(n) = 2 · S(n − 1), n ≥ 2.

(i) Expand: S(1) = 2, S(2) = 2 · 2 = 4, S(3) = 2 · S(2) = 8, . . . .

(ii) Guess: S(n) = 2n

(iii) Verify: Using Induction!BASIS: n = 1

LHS = 2

RHS = 21

= 2

Since LHS=RHS, the basis is proven.INDUCTIVE STEP: Assume that S(k) = 2k . We need to show that S(k + 1) = 2k+1. Observe that,

S(k + 1) = 2 · S(k), by definition

= 2 · 2k, by inductive hypothesis

= 2k+1!

Applying the first principle of mathematical induction, we conclude that S(n) = 2n .

Subramani Recursion

Page 32: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

EGV

ExampleConsider the recurrence:

S(1) = 2

S(n) = 2 · S(n − 1), n ≥ 2.

(i) Expand: S(1) = 2, S(2) = 2 · 2 = 4, S(3) = 2 · S(2) = 8, . . . .

(ii) Guess: S(n) = 2n

(iii) Verify: Using Induction!BASIS: n = 1

LHS = 2

RHS = 21

= 2

Since LHS=RHS, the basis is proven.INDUCTIVE STEP: Assume that S(k) = 2k . We need to show that S(k + 1) = 2k+1. Observe that,

S(k + 1) = 2 · S(k), by definition

= 2 · 2k, by inductive hypothesis

= 2k+1!

Applying the first principle of mathematical induction, we conclude that S(n) = 2n .

Subramani Recursion

Page 33: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

EGV (contd.)

Example

Solve the recurrence:

T (1) = 1

T (n) = T (n − 1) + 3, n ≥ 2.

(i) Expand: T (1) = 1, T (2) = T (1) + 3 = 4, T (3) = 3 + T (n − 2) = 7, . . .

(ii) Guess: T (n) = 3 · n − 2.

(iii) Verify: Somebody from class!

Subramani Recursion

Page 34: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

EGV (contd.)

Example

Solve the recurrence:

T (1) = 1

T (n) = T (n − 1) + 3, n ≥ 2.

(i) Expand: T (1) = 1,

T (2) = T (1) + 3 = 4, T (3) = 3 + T (n − 2) = 7, . . .

(ii) Guess: T (n) = 3 · n − 2.

(iii) Verify: Somebody from class!

Subramani Recursion

Page 35: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

EGV (contd.)

Example

Solve the recurrence:

T (1) = 1

T (n) = T (n − 1) + 3, n ≥ 2.

(i) Expand: T (1) = 1, T (2) = T (1) + 3 = 4,

T (3) = 3 + T (n − 2) = 7, . . .

(ii) Guess: T (n) = 3 · n − 2.

(iii) Verify: Somebody from class!

Subramani Recursion

Page 36: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

EGV (contd.)

Example

Solve the recurrence:

T (1) = 1

T (n) = T (n − 1) + 3, n ≥ 2.

(i) Expand: T (1) = 1, T (2) = T (1) + 3 = 4, T (3) = 3 + T (n − 2) = 7,

. . .

(ii) Guess: T (n) = 3 · n − 2.

(iii) Verify: Somebody from class!

Subramani Recursion

Page 37: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

EGV (contd.)

Example

Solve the recurrence:

T (1) = 1

T (n) = T (n − 1) + 3, n ≥ 2.

(i) Expand: T (1) = 1, T (2) = T (1) + 3 = 4, T (3) = 3 + T (n − 2) = 7, . . .

(ii) Guess: T (n) = 3 · n − 2.

(iii) Verify: Somebody from class!

Subramani Recursion

Page 38: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

EGV (contd.)

Example

Solve the recurrence:

T (1) = 1

T (n) = T (n − 1) + 3, n ≥ 2.

(i) Expand: T (1) = 1, T (2) = T (1) + 3 = 4, T (3) = 3 + T (n − 2) = 7, . . .

(ii) Guess: T (n) = 3 · n − 2.

(iii) Verify: Somebody from class!

Subramani Recursion

Page 39: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

EGV (contd.)

Example

Solve the recurrence:

T (1) = 1

T (n) = T (n − 1) + 3, n ≥ 2.

(i) Expand: T (1) = 1, T (2) = T (1) + 3 = 4, T (3) = 3 + T (n − 2) = 7, . . .

(ii) Guess: T (n) = 3 · n − 2.

(iii) Verify: Somebody from class!

Subramani Recursion

Page 40: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

Formula approach

Definition

A general linear recurrence has the form:

S(n) = f1(n) · S(n − 1) + f2(n) · S(n − 2) + . . . fk (n) · S(n − k) + g(n)

Note

The above formula is called linear, because the S() terms occur only in the first power.It is called first-order, if S(n) depends only on S(n − 1).For example, S(n) = c · S(n − 1) + g(n). The recurrence is called homogeneous, ifg(n) = 0, for all n.

Formula for Linear first-order recurrence

S(1) = k0

S(n) = c · S(n − 1) + g(n)

⇒ S(n) = cn−1 · k0 +∑n

i=2 cn−i · g(i).

Subramani Recursion

Page 41: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

Formula approach

Definition

A general linear recurrence has the form:

S(n) = f1(n) · S(n − 1) + f2(n) · S(n − 2) + . . . fk (n) · S(n − k) + g(n)

Note

The above formula is called linear, because the S() terms occur only in the first power.It is called first-order, if S(n) depends only on S(n − 1).For example, S(n) = c · S(n − 1) + g(n). The recurrence is called homogeneous, ifg(n) = 0, for all n.

Formula for Linear first-order recurrence

S(1) = k0

S(n) = c · S(n − 1) + g(n)

⇒ S(n) = cn−1 · k0 +∑n

i=2 cn−i · g(i).

Subramani Recursion

Page 42: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

Formula approach

Definition

A general linear recurrence has the form:

S(n) = f1(n) · S(n − 1) + f2(n) · S(n − 2) + . . . fk (n) · S(n − k) + g(n)

Note

The above formula is called linear, because the S() terms occur only in the first power.

It is called first-order, if S(n) depends only on S(n − 1).For example, S(n) = c · S(n − 1) + g(n). The recurrence is called homogeneous, ifg(n) = 0, for all n.

Formula for Linear first-order recurrence

S(1) = k0

S(n) = c · S(n − 1) + g(n)

⇒ S(n) = cn−1 · k0 +∑n

i=2 cn−i · g(i).

Subramani Recursion

Page 43: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

Formula approach

Definition

A general linear recurrence has the form:

S(n) = f1(n) · S(n − 1) + f2(n) · S(n − 2) + . . . fk (n) · S(n − k) + g(n)

Note

The above formula is called linear, because the S() terms occur only in the first power.It is called first-order, if S(n) depends only on S(n − 1).

For example, S(n) = c · S(n − 1) + g(n). The recurrence is called homogeneous, ifg(n) = 0, for all n.

Formula for Linear first-order recurrence

S(1) = k0

S(n) = c · S(n − 1) + g(n)

⇒ S(n) = cn−1 · k0 +∑n

i=2 cn−i · g(i).

Subramani Recursion

Page 44: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

Formula approach

Definition

A general linear recurrence has the form:

S(n) = f1(n) · S(n − 1) + f2(n) · S(n − 2) + . . . fk (n) · S(n − k) + g(n)

Note

The above formula is called linear, because the S() terms occur only in the first power.It is called first-order, if S(n) depends only on S(n − 1).For example, S(n) = c · S(n − 1) + g(n).

The recurrence is called homogeneous, ifg(n) = 0, for all n.

Formula for Linear first-order recurrence

S(1) = k0

S(n) = c · S(n − 1) + g(n)

⇒ S(n) = cn−1 · k0 +∑n

i=2 cn−i · g(i).

Subramani Recursion

Page 45: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

Formula approach

Definition

A general linear recurrence has the form:

S(n) = f1(n) · S(n − 1) + f2(n) · S(n − 2) + . . . fk (n) · S(n − k) + g(n)

Note

The above formula is called linear, because the S() terms occur only in the first power.It is called first-order, if S(n) depends only on S(n − 1).For example, S(n) = c · S(n − 1) + g(n). The recurrence is called homogeneous, ifg(n) = 0, for all n.

Formula for Linear first-order recurrence

S(1) = k0

S(n) = c · S(n − 1) + g(n)

⇒ S(n) = cn−1 · k0 +∑n

i=2 cn−i · g(i).

Subramani Recursion

Page 46: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

Formula approach

Definition

A general linear recurrence has the form:

S(n) = f1(n) · S(n − 1) + f2(n) · S(n − 2) + . . . fk (n) · S(n − k) + g(n)

Note

The above formula is called linear, because the S() terms occur only in the first power.It is called first-order, if S(n) depends only on S(n − 1).For example, S(n) = c · S(n − 1) + g(n). The recurrence is called homogeneous, ifg(n) = 0, for all n.

Formula for Linear first-order recurrence

S(1) = k0

S(n) = c · S(n − 1) + g(n)

⇒ S(n) = cn−1 · k0 +∑n

i=2 cn−i · g(i).

Subramani Recursion

Page 47: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

Formula approach

Definition

A general linear recurrence has the form:

S(n) = f1(n) · S(n − 1) + f2(n) · S(n − 2) + . . . fk (n) · S(n − k) + g(n)

Note

The above formula is called linear, because the S() terms occur only in the first power.It is called first-order, if S(n) depends only on S(n − 1).For example, S(n) = c · S(n − 1) + g(n). The recurrence is called homogeneous, ifg(n) = 0, for all n.

Formula for Linear first-order recurrence

S(1) = k0

S(n) = c · S(n − 1) + g(n)

⇒ S(n) = cn−1 · k0 +∑n

i=2 cn−i · g(i).

Subramani Recursion

Page 48: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

Formula approach

Definition

A general linear recurrence has the form:

S(n) = f1(n) · S(n − 1) + f2(n) · S(n − 2) + . . . fk (n) · S(n − k) + g(n)

Note

The above formula is called linear, because the S() terms occur only in the first power.It is called first-order, if S(n) depends only on S(n − 1).For example, S(n) = c · S(n − 1) + g(n). The recurrence is called homogeneous, ifg(n) = 0, for all n.

Formula for Linear first-order recurrence

S(1) = k0

S(n) = c · S(n − 1) + g(n)

⇒ S(n) = cn−1 · k0 +∑n

i=2 cn−i · g(i).

Subramani Recursion

Page 49: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

Formula approach

Definition

A general linear recurrence has the form:

S(n) = f1(n) · S(n − 1) + f2(n) · S(n − 2) + . . . fk (n) · S(n − k) + g(n)

Note

The above formula is called linear, because the S() terms occur only in the first power.It is called first-order, if S(n) depends only on S(n − 1).For example, S(n) = c · S(n − 1) + g(n). The recurrence is called homogeneous, ifg(n) = 0, for all n.

Formula for Linear first-order recurrence

S(1) = k0

S(n) = c · S(n − 1) + g(n)

⇒ S(n) = cn−1 · k0 +∑n

i=2 cn−i · g(i).

Subramani Recursion

Page 50: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

Linear first-order recurrence

Example

S(1) = 2

S(n) = 2 · S(n − 1), n ≥ 2.

As per the formula, k0 = 2, g(n) = 0 and c = 2. Thus,

S(n) = 2n−1 · 2 +n∑

i=2

2n−i · 0

= 2n

Subramani Recursion

Page 51: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

Linear first-order recurrence

Example

S(1) = 2

S(n) = 2 · S(n − 1), n ≥ 2.

As per the formula, k0 =

2, g(n) = 0 and c = 2. Thus,

S(n) = 2n−1 · 2 +n∑

i=2

2n−i · 0

= 2n

Subramani Recursion

Page 52: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

Linear first-order recurrence

Example

S(1) = 2

S(n) = 2 · S(n − 1), n ≥ 2.

As per the formula, k0 = 2, g(n) =

0 and c = 2. Thus,

S(n) = 2n−1 · 2 +n∑

i=2

2n−i · 0

= 2n

Subramani Recursion

Page 53: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

Linear first-order recurrence

Example

S(1) = 2

S(n) = 2 · S(n − 1), n ≥ 2.

As per the formula, k0 = 2, g(n) = 0 and c =

2. Thus,

S(n) = 2n−1 · 2 +n∑

i=2

2n−i · 0

= 2n

Subramani Recursion

Page 54: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

Linear first-order recurrence

Example

S(1) = 2

S(n) = 2 · S(n − 1), n ≥ 2.

As per the formula, k0 = 2, g(n) = 0 and c = 2. Thus,

S(n) = 2n−1 · 2 +n∑

i=2

2n−i · 0

= 2n

Subramani Recursion

Page 55: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

Linear first-order recurrence

Example

S(1) = 2

S(n) = 2 · S(n − 1), n ≥ 2.

As per the formula, k0 = 2, g(n) = 0 and c = 2. Thus,

S(n) =

2n−1 · 2 +n∑

i=2

2n−i · 0

= 2n

Subramani Recursion

Page 56: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

Linear first-order recurrence

Example

S(1) = 2

S(n) = 2 · S(n − 1), n ≥ 2.

As per the formula, k0 = 2, g(n) = 0 and c = 2. Thus,

S(n) = 2n−1 · 2 +n∑

i=2

2n−i · 0

= 2n

Subramani Recursion

Page 57: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

Linear first-order recurrence

Example

S(1) = 2

S(n) = 2 · S(n − 1), n ≥ 2.

As per the formula, k0 = 2, g(n) = 0 and c = 2. Thus,

S(n) = 2n−1 · 2 +n∑

i=2

2n−i · 0

= 2n

Subramani Recursion

Page 58: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

Another Example

Example

Solve the recurrence:

S(1) = 4

S(n) = 2 · S(n − 1) + 3, n ≥ 2.

As per the formula, k0 = 4, g(n) = 3 and c = 2. Thus,

S(n) = 2n−1 · 4 +n∑

i=2

2n−i · 3

= 2n+1 + 3n∑

i=2

2n−i

= 2n+1 + 3 · [2n−2 + 2n−3 + . . .+ 20]

= 2n+1 + 3 · [2n−1 − 1]

Subramani Recursion

Page 59: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

Another Example

Example

Solve the recurrence:

S(1) = 4

S(n) = 2 · S(n − 1) + 3, n ≥ 2.

As per the formula, k0 =

4, g(n) = 3 and c = 2. Thus,

S(n) = 2n−1 · 4 +n∑

i=2

2n−i · 3

= 2n+1 + 3n∑

i=2

2n−i

= 2n+1 + 3 · [2n−2 + 2n−3 + . . .+ 20]

= 2n+1 + 3 · [2n−1 − 1]

Subramani Recursion

Page 60: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

Another Example

Example

Solve the recurrence:

S(1) = 4

S(n) = 2 · S(n − 1) + 3, n ≥ 2.

As per the formula, k0 = 4, g(n) =

3 and c = 2. Thus,

S(n) = 2n−1 · 4 +n∑

i=2

2n−i · 3

= 2n+1 + 3n∑

i=2

2n−i

= 2n+1 + 3 · [2n−2 + 2n−3 + . . .+ 20]

= 2n+1 + 3 · [2n−1 − 1]

Subramani Recursion

Page 61: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

Another Example

Example

Solve the recurrence:

S(1) = 4

S(n) = 2 · S(n − 1) + 3, n ≥ 2.

As per the formula, k0 = 4, g(n) = 3 and c =

2. Thus,

S(n) = 2n−1 · 4 +n∑

i=2

2n−i · 3

= 2n+1 + 3n∑

i=2

2n−i

= 2n+1 + 3 · [2n−2 + 2n−3 + . . .+ 20]

= 2n+1 + 3 · [2n−1 − 1]

Subramani Recursion

Page 62: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

Another Example

Example

Solve the recurrence:

S(1) = 4

S(n) = 2 · S(n − 1) + 3, n ≥ 2.

As per the formula, k0 = 4, g(n) = 3 and c = 2. Thus,

S(n) = 2n−1 · 4 +n∑

i=2

2n−i · 3

= 2n+1 + 3n∑

i=2

2n−i

= 2n+1 + 3 · [2n−2 + 2n−3 + . . .+ 20]

= 2n+1 + 3 · [2n−1 − 1]

Subramani Recursion

Page 63: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

Another Example

Example

Solve the recurrence:

S(1) = 4

S(n) = 2 · S(n − 1) + 3, n ≥ 2.

As per the formula, k0 = 4, g(n) = 3 and c = 2. Thus,

S(n) =

2n−1 · 4 +n∑

i=2

2n−i · 3

= 2n+1 + 3n∑

i=2

2n−i

= 2n+1 + 3 · [2n−2 + 2n−3 + . . .+ 20]

= 2n+1 + 3 · [2n−1 − 1]

Subramani Recursion

Page 64: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

Another Example

Example

Solve the recurrence:

S(1) = 4

S(n) = 2 · S(n − 1) + 3, n ≥ 2.

As per the formula, k0 = 4, g(n) = 3 and c = 2. Thus,

S(n) = 2n−1 · 4 +n∑

i=2

2n−i · 3

= 2n+1 + 3n∑

i=2

2n−i

= 2n+1 + 3 · [2n−2 + 2n−3 + . . .+ 20]

= 2n+1 + 3 · [2n−1 − 1]

Subramani Recursion

Page 65: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

Another Example

Example

Solve the recurrence:

S(1) = 4

S(n) = 2 · S(n − 1) + 3, n ≥ 2.

As per the formula, k0 = 4, g(n) = 3 and c = 2. Thus,

S(n) = 2n−1 · 4 +n∑

i=2

2n−i · 3

= 2n+1 + 3n∑

i=2

2n−i

= 2n+1 + 3 · [2n−2 + 2n−3 + . . .+ 20]

= 2n+1 + 3 · [2n−1 − 1]

Subramani Recursion

Page 66: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

Another Example

Example

Solve the recurrence:

S(1) = 4

S(n) = 2 · S(n − 1) + 3, n ≥ 2.

As per the formula, k0 = 4, g(n) = 3 and c = 2. Thus,

S(n) = 2n−1 · 4 +n∑

i=2

2n−i · 3

= 2n+1 + 3n∑

i=2

2n−i

= 2n+1 + 3 · [2n−2 + 2n−3 + . . .+ 20]

= 2n+1 + 3 · [2n−1 − 1]

Subramani Recursion

Page 67: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

Another Example

Example

Solve the recurrence:

S(1) = 4

S(n) = 2 · S(n − 1) + 3, n ≥ 2.

As per the formula, k0 = 4, g(n) = 3 and c = 2. Thus,

S(n) = 2n−1 · 4 +n∑

i=2

2n−i · 3

= 2n+1 + 3n∑

i=2

2n−i

= 2n+1 + 3 · [2n−2 + 2n−3 + . . .+ 20]

= 2n+1 + 3 · [2n−1 − 1]

Subramani Recursion

Page 68: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

Second Order homogeneous Linear Recurrence with constantcoefficients

Formula

(i) Form: S(n) = c1 · S(n − 1) + c2 · S(n − 2), subject to some initial conditions.

(ii) Solve the characteristic equation: t2 − c1 · t − c2 = 0. Let r1 and r2 denote theroots.(a) If r1 6= r2, solve

p + q = S(1)

p · r1 + q · r2 = S(2)

Then, S(n) = p · rn−11 + q · rn−1

2(b) If r1 = r2 = r , solve

p = S(1)

(p + q) · r = S(2)

Then, S(n) = p · rn−1 + q · (n − 1) · rn−1

Subramani Recursion

Page 69: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

Second Order homogeneous Linear Recurrence with constantcoefficients

Formula

(i) Form: S(n) = c1 · S(n − 1) + c2 · S(n − 2), subject to some initial conditions.

(ii) Solve the characteristic equation: t2 − c1 · t − c2 = 0. Let r1 and r2 denote theroots.(a) If r1 6= r2, solve

p + q = S(1)

p · r1 + q · r2 = S(2)

Then, S(n) = p · rn−11 + q · rn−1

2(b) If r1 = r2 = r , solve

p = S(1)

(p + q) · r = S(2)

Then, S(n) = p · rn−1 + q · (n − 1) · rn−1

Subramani Recursion

Page 70: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

Second Order homogeneous Linear Recurrence with constantcoefficients

Formula

(i) Form: S(n) = c1 · S(n − 1) + c2 · S(n − 2), subject to some initial conditions.

(ii) Solve the characteristic equation: t2 − c1 · t − c2 = 0. Let r1 and r2 denote theroots.

(a) If r1 6= r2, solve

p + q = S(1)

p · r1 + q · r2 = S(2)

Then, S(n) = p · rn−11 + q · rn−1

2(b) If r1 = r2 = r , solve

p = S(1)

(p + q) · r = S(2)

Then, S(n) = p · rn−1 + q · (n − 1) · rn−1

Subramani Recursion

Page 71: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

Second Order homogeneous Linear Recurrence with constantcoefficients

Formula

(i) Form: S(n) = c1 · S(n − 1) + c2 · S(n − 2), subject to some initial conditions.

(ii) Solve the characteristic equation: t2 − c1 · t − c2 = 0. Let r1 and r2 denote theroots.

(a) If r1 6= r2, solve

p + q = S(1)

p · r1 + q · r2 = S(2)

Then, S(n) = p · rn−11 + q · rn−1

2(b) If r1 = r2 = r , solve

p = S(1)

(p + q) · r = S(2)

Then, S(n) = p · rn−1 + q · (n − 1) · rn−1

Subramani Recursion

Page 72: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

Second Order homogeneous Linear Recurrence with constantcoefficients

Formula

(i) Form: S(n) = c1 · S(n − 1) + c2 · S(n − 2), subject to some initial conditions.

(ii) Solve the characteristic equation: t2 − c1 · t − c2 = 0. Let r1 and r2 denote theroots.(a) If r1 6= r2, solve

p + q = S(1)

p · r1 + q · r2 = S(2)

Then, S(n) = p · rn−11 + q · rn−1

2(b) If r1 = r2 = r , solve

p = S(1)

(p + q) · r = S(2)

Then, S(n) = p · rn−1 + q · (n − 1) · rn−1

Subramani Recursion

Page 73: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

Second Order homogeneous Linear Recurrence with constantcoefficients

Formula

(i) Form: S(n) = c1 · S(n − 1) + c2 · S(n − 2), subject to some initial conditions.

(ii) Solve the characteristic equation: t2 − c1 · t − c2 = 0. Let r1 and r2 denote theroots.(a) If r1 6= r2, solve

p + q = S(1)

p · r1 + q · r2 = S(2)

Then, S(n) = p · rn−11 + q · rn−1

2

(b) If r1 = r2 = r , solve

p = S(1)

(p + q) · r = S(2)

Then, S(n) = p · rn−1 + q · (n − 1) · rn−1

Subramani Recursion

Page 74: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

Second Order homogeneous Linear Recurrence with constantcoefficients

Formula

(i) Form: S(n) = c1 · S(n − 1) + c2 · S(n − 2), subject to some initial conditions.

(ii) Solve the characteristic equation: t2 − c1 · t − c2 = 0. Let r1 and r2 denote theroots.(a) If r1 6= r2, solve

p + q = S(1)

p · r1 + q · r2 = S(2)

Then, S(n) = p · rn−11 + q · rn−1

2(b) If r1 = r2 = r , solve

p = S(1)

(p + q) · r = S(2)

Then, S(n) = p · rn−1 + q · (n − 1) · rn−1

Subramani Recursion

Page 75: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

Second Order homogeneous Linear Recurrence with constantcoefficients

Formula

(i) Form: S(n) = c1 · S(n − 1) + c2 · S(n − 2), subject to some initial conditions.

(ii) Solve the characteristic equation: t2 − c1 · t − c2 = 0. Let r1 and r2 denote theroots.(a) If r1 6= r2, solve

p + q = S(1)

p · r1 + q · r2 = S(2)

Then, S(n) = p · rn−11 + q · rn−1

2(b) If r1 = r2 = r , solve

p = S(1)

(p + q) · r = S(2)

Then, S(n) = p · rn−1 + q · (n − 1) · rn−1

Subramani Recursion

Page 76: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

Examples of second order recurrences

Example

Solve the recurrence relation

T (1) = 5

T (2) = 13

T (n) = 6 · T (n − 1)− 5 · T (n − 2), n ≥ 3

Solution:

(i) c1 = 6, c2 = −5. Characteristic equation: t2 − 6 · t + 5 = 0.Solution is: r1 = 1, r2 = 5.

(ii) Solve the equations:

p + q = T (1) = 5

p · 1 + q · 5 = T (2) = 13

We get p = 3 and q = 2.

(iii) Accordingly, the solution is T (n) = 3 · 1n−1 + 2 · 5n−1 = 3 + 2 · 5n−1.

Subramani Recursion

Page 77: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

Examples of second order recurrences

Example

Solve the recurrence relation

T (1) = 5

T (2) = 13

T (n) = 6 · T (n − 1)− 5 · T (n − 2), n ≥ 3

Solution:

(i) c1 = 6, c2 = −5. Characteristic equation: t2 − 6 · t + 5 = 0.Solution is: r1 = 1, r2 = 5.

(ii) Solve the equations:

p + q = T (1) = 5

p · 1 + q · 5 = T (2) = 13

We get p = 3 and q = 2.

(iii) Accordingly, the solution is T (n) = 3 · 1n−1 + 2 · 5n−1 = 3 + 2 · 5n−1.

Subramani Recursion

Page 78: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

Examples of second order recurrences

Example

Solve the recurrence relation

T (1) = 5

T (2) = 13

T (n) = 6 · T (n − 1)− 5 · T (n − 2), n ≥ 3

Solution:

(i) c1 = 6, c2 = −5.

Characteristic equation: t2 − 6 · t + 5 = 0.Solution is: r1 = 1, r2 = 5.

(ii) Solve the equations:

p + q = T (1) = 5

p · 1 + q · 5 = T (2) = 13

We get p = 3 and q = 2.

(iii) Accordingly, the solution is T (n) = 3 · 1n−1 + 2 · 5n−1 = 3 + 2 · 5n−1.

Subramani Recursion

Page 79: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

Examples of second order recurrences

Example

Solve the recurrence relation

T (1) = 5

T (2) = 13

T (n) = 6 · T (n − 1)− 5 · T (n − 2), n ≥ 3

Solution:

(i) c1 = 6, c2 = −5. Characteristic equation:

t2 − 6 · t + 5 = 0.Solution is: r1 = 1, r2 = 5.

(ii) Solve the equations:

p + q = T (1) = 5

p · 1 + q · 5 = T (2) = 13

We get p = 3 and q = 2.

(iii) Accordingly, the solution is T (n) = 3 · 1n−1 + 2 · 5n−1 = 3 + 2 · 5n−1.

Subramani Recursion

Page 80: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

Examples of second order recurrences

Example

Solve the recurrence relation

T (1) = 5

T (2) = 13

T (n) = 6 · T (n − 1)− 5 · T (n − 2), n ≥ 3

Solution:

(i) c1 = 6, c2 = −5. Characteristic equation: t2 − 6 · t + 5 = 0.

Solution is: r1 = 1, r2 = 5.

(ii) Solve the equations:

p + q = T (1) = 5

p · 1 + q · 5 = T (2) = 13

We get p = 3 and q = 2.

(iii) Accordingly, the solution is T (n) = 3 · 1n−1 + 2 · 5n−1 = 3 + 2 · 5n−1.

Subramani Recursion

Page 81: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

Examples of second order recurrences

Example

Solve the recurrence relation

T (1) = 5

T (2) = 13

T (n) = 6 · T (n − 1)− 5 · T (n − 2), n ≥ 3

Solution:

(i) c1 = 6, c2 = −5. Characteristic equation: t2 − 6 · t + 5 = 0.Solution is: r1 = 1, r2 = 5.

(ii) Solve the equations:

p + q = T (1) = 5

p · 1 + q · 5 = T (2) = 13

We get p = 3 and q = 2.

(iii) Accordingly, the solution is T (n) = 3 · 1n−1 + 2 · 5n−1 = 3 + 2 · 5n−1.

Subramani Recursion

Page 82: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

Examples of second order recurrences

Example

Solve the recurrence relation

T (1) = 5

T (2) = 13

T (n) = 6 · T (n − 1)− 5 · T (n − 2), n ≥ 3

Solution:

(i) c1 = 6, c2 = −5. Characteristic equation: t2 − 6 · t + 5 = 0.Solution is: r1 = 1, r2 = 5.

(ii) Solve the equations:

p + q = T (1) = 5

p · 1 + q · 5 = T (2) = 13

We get p = 3 and q = 2.

(iii) Accordingly, the solution is T (n) = 3 · 1n−1 + 2 · 5n−1 = 3 + 2 · 5n−1.

Subramani Recursion

Page 83: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

Examples of second order recurrences

Example

Solve the recurrence relation

T (1) = 5

T (2) = 13

T (n) = 6 · T (n − 1)− 5 · T (n − 2), n ≥ 3

Solution:

(i) c1 = 6, c2 = −5. Characteristic equation: t2 − 6 · t + 5 = 0.Solution is: r1 = 1, r2 = 5.

(ii) Solve the equations:

p + q = T (1) = 5

p · 1 + q · 5 = T (2) = 13

We get p = 3 and q = 2.

(iii) Accordingly, the solution is T (n) = 3 · 1n−1 + 2 · 5n−1 = 3 + 2 · 5n−1.

Subramani Recursion

Page 84: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

Examples of second order recurrences

Example

Solve the recurrence relation

T (1) = 5

T (2) = 13

T (n) = 6 · T (n − 1)− 5 · T (n − 2), n ≥ 3

Solution:

(i) c1 = 6, c2 = −5. Characteristic equation: t2 − 6 · t + 5 = 0.Solution is: r1 = 1, r2 = 5.

(ii) Solve the equations:

p + q = T (1) = 5

p · 1 + q · 5 = T (2) = 13

We get p = 3 and q = 2.

(iii) Accordingly, the solution is T (n) = 3 · 1n−1 + 2 · 5n−1 = 3 + 2 · 5n−1.

Subramani Recursion

Page 85: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

One More Example

Example

Solve the recurrence relation:

S(1) = 1

S(2) = 12

S(n) = 8 · S(n − 1)− 16 · S(n − 2), n ≥ 3

Solution:

(i) c1 = 8, c2 = −16. Characteristic equation: t2 − 8t + 16 = 0. Solution isr1 = r2 = 4.

(ii) Solve the equations:

p = 1

p · 4 + q · 4 = 12

We get p = 1 and q = 2.

(iii) Accordingly, the solution is S(n) = 4n−1 + 2 · (n − 1) · 4n−1 = (2n − 1) · 4n−1.

Subramani Recursion

Page 86: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

One More Example

Example

Solve the recurrence relation:

S(1) = 1

S(2) = 12

S(n) = 8 · S(n − 1)− 16 · S(n − 2), n ≥ 3

Solution:(i) c1 = 8, c2 = −16.

Characteristic equation: t2 − 8t + 16 = 0. Solution isr1 = r2 = 4.

(ii) Solve the equations:

p = 1

p · 4 + q · 4 = 12

We get p = 1 and q = 2.

(iii) Accordingly, the solution is S(n) = 4n−1 + 2 · (n − 1) · 4n−1 = (2n − 1) · 4n−1.

Subramani Recursion

Page 87: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

One More Example

Example

Solve the recurrence relation:

S(1) = 1

S(2) = 12

S(n) = 8 · S(n − 1)− 16 · S(n − 2), n ≥ 3

Solution:(i) c1 = 8, c2 = −16. Characteristic equation: t2 − 8t + 16 = 0.

Solution isr1 = r2 = 4.

(ii) Solve the equations:

p = 1

p · 4 + q · 4 = 12

We get p = 1 and q = 2.

(iii) Accordingly, the solution is S(n) = 4n−1 + 2 · (n − 1) · 4n−1 = (2n − 1) · 4n−1.

Subramani Recursion

Page 88: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

One More Example

Example

Solve the recurrence relation:

S(1) = 1

S(2) = 12

S(n) = 8 · S(n − 1)− 16 · S(n − 2), n ≥ 3

Solution:(i) c1 = 8, c2 = −16. Characteristic equation: t2 − 8t + 16 = 0. Solution is

r1 = r2 = 4.

(ii) Solve the equations:

p = 1

p · 4 + q · 4 = 12

We get p = 1 and q = 2.

(iii) Accordingly, the solution is S(n) = 4n−1 + 2 · (n − 1) · 4n−1 = (2n − 1) · 4n−1.

Subramani Recursion

Page 89: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

One More Example

Example

Solve the recurrence relation:

S(1) = 1

S(2) = 12

S(n) = 8 · S(n − 1)− 16 · S(n − 2), n ≥ 3

Solution:(i) c1 = 8, c2 = −16. Characteristic equation: t2 − 8t + 16 = 0. Solution is

r1 = r2 = 4.

(ii) Solve the equations:

p = 1

p · 4 + q · 4 = 12

We get p = 1 and q = 2.

(iii) Accordingly, the solution is S(n) = 4n−1 + 2 · (n − 1) · 4n−1 = (2n − 1) · 4n−1.

Subramani Recursion

Page 90: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

One More Example

Example

Solve the recurrence relation:

S(1) = 1

S(2) = 12

S(n) = 8 · S(n − 1)− 16 · S(n − 2), n ≥ 3

Solution:(i) c1 = 8, c2 = −16. Characteristic equation: t2 − 8t + 16 = 0. Solution is

r1 = r2 = 4.

(ii) Solve the equations:

p = 1

p · 4 + q · 4 = 12

We get p = 1 and q = 2.

(iii) Accordingly, the solution is S(n) = 4n−1 + 2 · (n − 1) · 4n−1 = (2n − 1) · 4n−1.

Subramani Recursion

Page 91: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

One More Example

Example

Solve the recurrence relation:

S(1) = 1

S(2) = 12

S(n) = 8 · S(n − 1)− 16 · S(n − 2), n ≥ 3

Solution:(i) c1 = 8, c2 = −16. Characteristic equation: t2 − 8t + 16 = 0. Solution is

r1 = r2 = 4.

(ii) Solve the equations:

p = 1

p · 4 + q · 4 = 12

We get p = 1 and q = 2.

(iii) Accordingly, the solution is S(n) = 4n−1 + 2 · (n − 1) · 4n−1 = (2n − 1) · 4n−1.

Subramani Recursion

Page 92: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

Divide and Conquer Recurrence

Formula for Divide and Conquer Recurrence

S(1) = k0

S(n) = c · S(n2

) + g(n), n ≥ 2, n = 2m

⇒ S(n) = c log n · k0 +∑log n

i=1 c logn−i · g(2i ). (All logarithms are to base 2).

ExampleSolve the recurrence:

C(1) = 1

C(n) = 1 + C(n

2), n ≥ 2, n = 2m

Note that k0 = 1, c = 1 and g(i) = 1, ∀i . As per the formula,

C(n) = 1log n · 1 +

log n∑i=1

1log n−i · (1)

= 1 + (log n) · 1

= 1 + log n

Subramani Recursion

Page 93: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

Divide and Conquer Recurrence

Formula for Divide and Conquer Recurrence

S(1) = k0

S(n) = c · S(n2

) + g(n), n ≥ 2, n = 2m

⇒ S(n) = c log n · k0 +∑log n

i=1 c logn−i · g(2i ). (All logarithms are to base 2).

ExampleSolve the recurrence:

C(1) = 1

C(n) = 1 + C(n

2), n ≥ 2, n = 2m

Note that k0 = 1, c = 1 and g(i) = 1, ∀i . As per the formula,

C(n) = 1log n · 1 +

log n∑i=1

1log n−i · (1)

= 1 + (log n) · 1

= 1 + log n

Subramani Recursion

Page 94: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

Divide and Conquer Recurrence

Formula for Divide and Conquer Recurrence

S(1) = k0

S(n) = c · S(n2

) + g(n), n ≥ 2, n = 2m

⇒ S(n) = c log n · k0 +∑log n

i=1 c logn−i · g(2i ).

(All logarithms are to base 2).

ExampleSolve the recurrence:

C(1) = 1

C(n) = 1 + C(n

2), n ≥ 2, n = 2m

Note that k0 = 1, c = 1 and g(i) = 1, ∀i . As per the formula,

C(n) = 1log n · 1 +

log n∑i=1

1log n−i · (1)

= 1 + (log n) · 1

= 1 + log n

Subramani Recursion

Page 95: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

Divide and Conquer Recurrence

Formula for Divide and Conquer Recurrence

S(1) = k0

S(n) = c · S(n2

) + g(n), n ≥ 2, n = 2m

⇒ S(n) = c log n · k0 +∑log n

i=1 c logn−i · g(2i ). (All logarithms are to base 2).

ExampleSolve the recurrence:

C(1) = 1

C(n) = 1 + C(n

2), n ≥ 2, n = 2m

Note that k0 = 1, c = 1 and g(i) = 1, ∀i . As per the formula,

C(n) = 1log n · 1 +

log n∑i=1

1log n−i · (1)

= 1 + (log n) · 1

= 1 + log n

Subramani Recursion

Page 96: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

Divide and Conquer Recurrence

Formula for Divide and Conquer Recurrence

S(1) = k0

S(n) = c · S(n2

) + g(n), n ≥ 2, n = 2m

⇒ S(n) = c log n · k0 +∑log n

i=1 c logn−i · g(2i ). (All logarithms are to base 2).

ExampleSolve the recurrence:

C(1) = 1

C(n) = 1 + C(n

2), n ≥ 2, n = 2m

Note that k0 = 1, c = 1 and g(i) = 1, ∀i . As per the formula,

C(n) = 1log n · 1 +

log n∑i=1

1log n−i · (1)

= 1 + (log n) · 1

= 1 + log n

Subramani Recursion

Page 97: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

Divide and Conquer Recurrence

Formula for Divide and Conquer Recurrence

S(1) = k0

S(n) = c · S(n2

) + g(n), n ≥ 2, n = 2m

⇒ S(n) = c log n · k0 +∑log n

i=1 c logn−i · g(2i ). (All logarithms are to base 2).

ExampleSolve the recurrence:

C(1) = 1

C(n) = 1 + C(n

2), n ≥ 2, n = 2m

Note that k0 =

1, c = 1 and g(i) = 1, ∀i . As per the formula,

C(n) = 1log n · 1 +

log n∑i=1

1log n−i · (1)

= 1 + (log n) · 1

= 1 + log n

Subramani Recursion

Page 98: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

Divide and Conquer Recurrence

Formula for Divide and Conquer Recurrence

S(1) = k0

S(n) = c · S(n2

) + g(n), n ≥ 2, n = 2m

⇒ S(n) = c log n · k0 +∑log n

i=1 c logn−i · g(2i ). (All logarithms are to base 2).

ExampleSolve the recurrence:

C(1) = 1

C(n) = 1 + C(n

2), n ≥ 2, n = 2m

Note that k0 = 1, c =

1 and g(i) = 1, ∀i . As per the formula,

C(n) = 1log n · 1 +

log n∑i=1

1log n−i · (1)

= 1 + (log n) · 1

= 1 + log n

Subramani Recursion

Page 99: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

Divide and Conquer Recurrence

Formula for Divide and Conquer Recurrence

S(1) = k0

S(n) = c · S(n2

) + g(n), n ≥ 2, n = 2m

⇒ S(n) = c log n · k0 +∑log n

i=1 c logn−i · g(2i ). (All logarithms are to base 2).

ExampleSolve the recurrence:

C(1) = 1

C(n) = 1 + C(n

2), n ≥ 2, n = 2m

Note that k0 = 1, c = 1 and g(i) =

1, ∀i . As per the formula,

C(n) = 1log n · 1 +

log n∑i=1

1log n−i · (1)

= 1 + (log n) · 1

= 1 + log n

Subramani Recursion

Page 100: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

Divide and Conquer Recurrence

Formula for Divide and Conquer Recurrence

S(1) = k0

S(n) = c · S(n2

) + g(n), n ≥ 2, n = 2m

⇒ S(n) = c log n · k0 +∑log n

i=1 c logn−i · g(2i ). (All logarithms are to base 2).

ExampleSolve the recurrence:

C(1) = 1

C(n) = 1 + C(n

2), n ≥ 2, n = 2m

Note that k0 = 1, c = 1 and g(i) = 1, ∀i .

As per the formula,

C(n) = 1log n · 1 +

log n∑i=1

1log n−i · (1)

= 1 + (log n) · 1

= 1 + log n

Subramani Recursion

Page 101: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

Divide and Conquer Recurrence

Formula for Divide and Conquer Recurrence

S(1) = k0

S(n) = c · S(n2

) + g(n), n ≥ 2, n = 2m

⇒ S(n) = c log n · k0 +∑log n

i=1 c logn−i · g(2i ). (All logarithms are to base 2).

ExampleSolve the recurrence:

C(1) = 1

C(n) = 1 + C(n

2), n ≥ 2, n = 2m

Note that k0 = 1, c = 1 and g(i) = 1, ∀i . As per the formula,

C(n) = 1log n · 1 +

log n∑i=1

1log n−i · (1)

= 1 + (log n) · 1

= 1 + log n

Subramani Recursion

Page 102: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

Divide and Conquer Recurrence

Formula for Divide and Conquer Recurrence

S(1) = k0

S(n) = c · S(n2

) + g(n), n ≥ 2, n = 2m

⇒ S(n) = c log n · k0 +∑log n

i=1 c logn−i · g(2i ). (All logarithms are to base 2).

ExampleSolve the recurrence:

C(1) = 1

C(n) = 1 + C(n

2), n ≥ 2, n = 2m

Note that k0 = 1, c = 1 and g(i) = 1, ∀i . As per the formula,

C(n) = 1log n · 1 +

log n∑i=1

1log n−i · (1)

= 1 + (log n) · 1

= 1 + log n

Subramani Recursion

Page 103: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

Divide and Conquer Recurrence

Formula for Divide and Conquer Recurrence

S(1) = k0

S(n) = c · S(n2

) + g(n), n ≥ 2, n = 2m

⇒ S(n) = c log n · k0 +∑log n

i=1 c logn−i · g(2i ). (All logarithms are to base 2).

ExampleSolve the recurrence:

C(1) = 1

C(n) = 1 + C(n

2), n ≥ 2, n = 2m

Note that k0 = 1, c = 1 and g(i) = 1, ∀i . As per the formula,

C(n) = 1log n · 1 +

log n∑i=1

1log n−i · (1)

= 1 + (log n) · 1

= 1 + log n

Subramani Recursion

Page 104: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

Divide and Conquer Recurrence

Formula for Divide and Conquer Recurrence

S(1) = k0

S(n) = c · S(n2

) + g(n), n ≥ 2, n = 2m

⇒ S(n) = c log n · k0 +∑log n

i=1 c logn−i · g(2i ). (All logarithms are to base 2).

ExampleSolve the recurrence:

C(1) = 1

C(n) = 1 + C(n

2), n ≥ 2, n = 2m

Note that k0 = 1, c = 1 and g(i) = 1, ∀i . As per the formula,

C(n) = 1log n · 1 +

log n∑i=1

1log n−i · (1)

= 1 + (log n) · 1

= 1 + log n

Subramani Recursion

Page 105: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

ExampleSolve the recurrence:

T (1) = 3

T (n) = 2 · T (n

2) + 2 · n, n ≥ 2, n = 2m

Note that k0 = 3, c = 2 and g(i) = 2 · i, ∀i . As per the formula,

T (n) = 2log n · 3 +

log n∑i=1

2log n−i · 2 · (2i )

= 3 · 2log n +

log n∑i=1

2log n+1

= 3 · n + 2log n+1 · (log n)

= 3 · n + 2log n · 2 · log n

= 3 · n + n · 2 · log n, since (aloga n = n, a 6= 0)

= 3 · n + 2 · n · log n

Subramani Recursion

Page 106: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

ExampleSolve the recurrence:

T (1) = 3

T (n) = 2 · T (n

2) + 2 · n, n ≥ 2, n = 2m

Note that k0 = 3, c = 2 and g(i) = 2 · i, ∀i .

As per the formula,

T (n) = 2log n · 3 +

log n∑i=1

2log n−i · 2 · (2i )

= 3 · 2log n +

log n∑i=1

2log n+1

= 3 · n + 2log n+1 · (log n)

= 3 · n + 2log n · 2 · log n

= 3 · n + n · 2 · log n, since (aloga n = n, a 6= 0)

= 3 · n + 2 · n · log n

Subramani Recursion

Page 107: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

ExampleSolve the recurrence:

T (1) = 3

T (n) = 2 · T (n

2) + 2 · n, n ≥ 2, n = 2m

Note that k0 = 3, c = 2 and g(i) = 2 · i, ∀i . As per the formula,

T (n) = 2log n · 3 +

log n∑i=1

2log n−i · 2 · (2i )

= 3 · 2log n +

log n∑i=1

2log n+1

= 3 · n + 2log n+1 · (log n)

= 3 · n + 2log n · 2 · log n

= 3 · n + n · 2 · log n, since (aloga n = n, a 6= 0)

= 3 · n + 2 · n · log n

Subramani Recursion

Page 108: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

ExampleSolve the recurrence:

T (1) = 3

T (n) = 2 · T (n

2) + 2 · n, n ≥ 2, n = 2m

Note that k0 = 3, c = 2 and g(i) = 2 · i, ∀i . As per the formula,

T (n) = 2log n · 3 +

log n∑i=1

2log n−i · 2 · (2i )

= 3 · 2log n +

log n∑i=1

2log n+1

= 3 · n + 2log n+1 · (log n)

= 3 · n + 2log n · 2 · log n

= 3 · n + n · 2 · log n, since (aloga n = n, a 6= 0)

= 3 · n + 2 · n · log n

Subramani Recursion

Page 109: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

ExampleSolve the recurrence:

T (1) = 3

T (n) = 2 · T (n

2) + 2 · n, n ≥ 2, n = 2m

Note that k0 = 3, c = 2 and g(i) = 2 · i, ∀i . As per the formula,

T (n) = 2log n · 3 +

log n∑i=1

2log n−i · 2 · (2i )

= 3 · 2log n +

log n∑i=1

2log n+1

= 3 · n + 2log n+1 · (log n)

= 3 · n + 2log n · 2 · log n

= 3 · n + n · 2 · log n, since (aloga n = n, a 6= 0)

= 3 · n + 2 · n · log n

Subramani Recursion

Page 110: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

ExampleSolve the recurrence:

T (1) = 3

T (n) = 2 · T (n

2) + 2 · n, n ≥ 2, n = 2m

Note that k0 = 3, c = 2 and g(i) = 2 · i, ∀i . As per the formula,

T (n) = 2log n · 3 +

log n∑i=1

2log n−i · 2 · (2i )

= 3 · 2log n +

log n∑i=1

2log n+1

= 3 · n + 2log n+1 · (log n)

= 3 · n + 2log n · 2 · log n

= 3 · n + n · 2 · log n, since (aloga n = n, a 6= 0)

= 3 · n + 2 · n · log n

Subramani Recursion

Page 111: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

ExampleSolve the recurrence:

T (1) = 3

T (n) = 2 · T (n

2) + 2 · n, n ≥ 2, n = 2m

Note that k0 = 3, c = 2 and g(i) = 2 · i, ∀i . As per the formula,

T (n) = 2log n · 3 +

log n∑i=1

2log n−i · 2 · (2i )

= 3 · 2log n +

log n∑i=1

2log n+1

= 3 · n + 2log n+1 · (log n)

= 3 · n + 2log n · 2 · log n

= 3 · n + n · 2 · log n, since (aloga n = n, a 6= 0)

= 3 · n + 2 · n · log n

Subramani Recursion

Page 112: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

ExampleSolve the recurrence:

T (1) = 3

T (n) = 2 · T (n

2) + 2 · n, n ≥ 2, n = 2m

Note that k0 = 3, c = 2 and g(i) = 2 · i, ∀i . As per the formula,

T (n) = 2log n · 3 +

log n∑i=1

2log n−i · 2 · (2i )

= 3 · 2log n +

log n∑i=1

2log n+1

= 3 · n + 2log n+1 · (log n)

= 3 · n + 2log n · 2 · log n

= 3 · n + n · 2 · log n,

since (aloga n = n, a 6= 0)

= 3 · n + 2 · n · log n

Subramani Recursion

Page 113: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

ExampleSolve the recurrence:

T (1) = 3

T (n) = 2 · T (n

2) + 2 · n, n ≥ 2, n = 2m

Note that k0 = 3, c = 2 and g(i) = 2 · i, ∀i . As per the formula,

T (n) = 2log n · 3 +

log n∑i=1

2log n−i · 2 · (2i )

= 3 · 2log n +

log n∑i=1

2log n+1

= 3 · n + 2log n+1 · (log n)

= 3 · n + 2log n · 2 · log n

= 3 · n + n · 2 · log n, since (aloga n = n, a 6= 0)

= 3 · n + 2 · n · log n

Subramani Recursion

Page 114: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

ExampleSolve the recurrence:

T (1) = 3

T (n) = 2 · T (n

2) + 2 · n, n ≥ 2, n = 2m

Note that k0 = 3, c = 2 and g(i) = 2 · i, ∀i . As per the formula,

T (n) = 2log n · 3 +

log n∑i=1

2log n−i · 2 · (2i )

= 3 · 2log n +

log n∑i=1

2log n+1

= 3 · n + 2log n+1 · (log n)

= 3 · n + 2log n · 2 · log n

= 3 · n + n · 2 · log n, since (aloga n = n, a 6= 0)

= 3 · n + 2 · n · log n

Subramani Recursion

Page 115: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

The Master Method

Theorem

Let a ≥ 1 and b ≥ 1 be constants.

Let f (n) be a function and let T (n) be definedrecursively as follows:

T (n) = a · T (nb

) + f (n)

(i) If f (n) = O(nlogb a−ε), for some constant ε > 0, then T (n) = Θ(nlogb a).

(ii) If f (n) = Θ(nlogb a), then T (n) = Θ(nlogb a · log n).

(iii) If f (n) = Ω(nlogb a+ε), for some constant ε > 0, and if a · f ( nb ) ≤ c · f (n), for some

constant c < 1, then T (n) = Θ(f (n)).

Note

Proof is via induction. Outside scope of class. The master theorem does not cover allcases!

Subramani Recursion

Page 116: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

The Master Method

Theorem

Let a ≥ 1 and b ≥ 1 be constants. Let f (n) be a function and let T (n) be definedrecursively as follows:

T (n) = a · T (nb

) + f (n)

(i) If f (n) = O(nlogb a−ε), for some constant ε > 0, then T (n) = Θ(nlogb a).

(ii) If f (n) = Θ(nlogb a), then T (n) = Θ(nlogb a · log n).

(iii) If f (n) = Ω(nlogb a+ε), for some constant ε > 0, and if a · f ( nb ) ≤ c · f (n), for some

constant c < 1, then T (n) = Θ(f (n)).

Note

Proof is via induction. Outside scope of class. The master theorem does not cover allcases!

Subramani Recursion

Page 117: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

The Master Method

Theorem

Let a ≥ 1 and b ≥ 1 be constants. Let f (n) be a function and let T (n) be definedrecursively as follows:

T (n) = a · T (nb

) + f (n)

(i) If f (n) = O(nlogb a−ε), for some constant ε > 0, then T (n) = Θ(nlogb a).

(ii) If f (n) = Θ(nlogb a), then T (n) = Θ(nlogb a · log n).

(iii) If f (n) = Ω(nlogb a+ε), for some constant ε > 0, and if a · f ( nb ) ≤ c · f (n), for some

constant c < 1, then T (n) = Θ(f (n)).

Note

Proof is via induction. Outside scope of class. The master theorem does not cover allcases!

Subramani Recursion

Page 118: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

The Master Method

Theorem

Let a ≥ 1 and b ≥ 1 be constants. Let f (n) be a function and let T (n) be definedrecursively as follows:

T (n) = a · T (nb

) + f (n)

(i) If f (n) = O(nlogb a−ε), for some constant ε > 0, then T (n) = Θ(nlogb a).

(ii) If f (n) = Θ(nlogb a), then T (n) = Θ(nlogb a · log n).

(iii) If f (n) = Ω(nlogb a+ε), for some constant ε > 0, and if a · f ( nb ) ≤ c · f (n), for some

constant c < 1, then T (n) = Θ(f (n)).

Note

Proof is via induction. Outside scope of class. The master theorem does not cover allcases!

Subramani Recursion

Page 119: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

The Master Method

Theorem

Let a ≥ 1 and b ≥ 1 be constants. Let f (n) be a function and let T (n) be definedrecursively as follows:

T (n) = a · T (nb

) + f (n)

(i) If f (n) = O(nlogb a−ε), for some constant ε > 0, then T (n) = Θ(nlogb a).

(ii) If f (n) = Θ(nlogb a), then T (n) = Θ(nlogb a · log n).

(iii) If f (n) = Ω(nlogb a+ε), for some constant ε > 0, and if a · f ( nb ) ≤ c · f (n), for some

constant c < 1, then T (n) = Θ(f (n)).

Note

Proof is via induction. Outside scope of class. The master theorem does not cover allcases!

Subramani Recursion

Page 120: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

The Master Method

Theorem

Let a ≥ 1 and b ≥ 1 be constants. Let f (n) be a function and let T (n) be definedrecursively as follows:

T (n) = a · T (nb

) + f (n)

(i) If f (n) = O(nlogb a−ε), for some constant ε > 0, then T (n) = Θ(nlogb a).

(ii) If f (n) = Θ(nlogb a), then T (n) = Θ(nlogb a · log n).

(iii) If f (n) = Ω(nlogb a+ε), for some constant ε > 0, and if a · f ( nb ) ≤ c · f (n), for some

constant c < 1, then T (n) = Θ(f (n)).

Note

Proof is via induction. Outside scope of class. The master theorem does not cover allcases!

Subramani Recursion

Page 121: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

The Master Method

Theorem

Let a ≥ 1 and b ≥ 1 be constants. Let f (n) be a function and let T (n) be definedrecursively as follows:

T (n) = a · T (nb

) + f (n)

(i) If f (n) = O(nlogb a−ε), for some constant ε > 0, then T (n) = Θ(nlogb a).

(ii) If f (n) = Θ(nlogb a), then T (n) = Θ(nlogb a · log n).

(iii) If f (n) = Ω(nlogb a+ε), for some constant ε > 0, and if a · f ( nb ) ≤ c · f (n), for some

constant c < 1, then T (n) = Θ(f (n)).

Note

Proof is via induction. Outside scope of class.

The master theorem does not cover allcases!

Subramani Recursion

Page 122: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

The Master Method

Theorem

Let a ≥ 1 and b ≥ 1 be constants. Let f (n) be a function and let T (n) be definedrecursively as follows:

T (n) = a · T (nb

) + f (n)

(i) If f (n) = O(nlogb a−ε), for some constant ε > 0, then T (n) = Θ(nlogb a).

(ii) If f (n) = Θ(nlogb a), then T (n) = Θ(nlogb a · log n).

(iii) If f (n) = Ω(nlogb a+ε), for some constant ε > 0, and if a · f ( nb ) ≤ c · f (n), for some

constant c < 1, then T (n) = Θ(f (n)).

Note

Proof is via induction. Outside scope of class. The master theorem does not cover allcases!

Subramani Recursion

Page 123: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

Some examples

Example

(i) T (n) = 9 · T ( n3 ) + n.

(ii) T (n) = T ( 2n3 ) + 1.

(iii) T (n) = 3 · T ( n4 ) + n · log n.

(iv) T (n) = 2 · T ( n2 ) + n.

(v) T (n) = 2 · T (√

n) + log n.

Subramani Recursion

Page 124: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

Some examples

Example

(i) T (n) = 9 · T ( n3 ) + n.

(ii) T (n) = T ( 2n3 ) + 1.

(iii) T (n) = 3 · T ( n4 ) + n · log n.

(iv) T (n) = 2 · T ( n2 ) + n.

(v) T (n) = 2 · T (√

n) + log n.

Subramani Recursion

Page 125: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

Some examples

Example

(i) T (n) = 9 · T ( n3 ) + n.

(ii) T (n) = T ( 2n3 ) + 1.

(iii) T (n) = 3 · T ( n4 ) + n · log n.

(iv) T (n) = 2 · T ( n2 ) + n.

(v) T (n) = 2 · T (√

n) + log n.

Subramani Recursion

Page 126: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

Some examples

Example

(i) T (n) = 9 · T ( n3 ) + n.

(ii) T (n) = T ( 2n3 ) + 1.

(iii) T (n) = 3 · T ( n4 ) + n · log n.

(iv) T (n) = 2 · T ( n2 ) + n.

(v) T (n) = 2 · T (√

n) + log n.

Subramani Recursion

Page 127: Recurrence Relations - West Virginia Universitycommunity.Wvu.edu/~krsubramani/courses/sp11/doa/lecnotes/recurrences.pdfRecurrence Relations K. Subramani1 1Lane Department of Computer

RecurrencesSolving Recurrences

Some examples

Example

(i) T (n) = 9 · T ( n3 ) + n.

(ii) T (n) = T ( 2n3 ) + 1.

(iii) T (n) = 3 · T ( n4 ) + n · log n.

(iv) T (n) = 2 · T ( n2 ) + n.

(v) T (n) = 2 · T (√

n) + log n.

Subramani Recursion