Recursion

Docsity.com

Recursively defined sequences

To define a sequence recursively:

•give initial conditions, i.e., the values of the first

few terms explicitly;

•give a recurrence relation, i.e., an equation that

relates later terms in the sequence to earlier

terms.

Example:

•Define the following sequence recursively:

1, 4, 7, 10, 13, …

•Solution: a1 = 1, an = an-1 + 3 for n≥2

Docsity.com

Recursion is one of the central

ideas of computer science

To solve a problem recursively

•Break it down into smaller subproblems each

having the same form as the original problem;

•When the process is repeated many times, the

last of the subproblems are small and easy to

solve;

•The solutions of the subproblems can be woven

together to form a solution to the original problem.

•Example: The tower of Hanoi

Docsity.com

RULES:

You may only move one disk at a time.

A disk may only be moved to one of the three columns.

You must never place a larger disk on top of a smaller disk.

INITIAL STATE GOAL STATE

Tower of Hanoi:

Move disks from left pole to right pole

Pole A Pole B Pole C Pole A Pole B Pole C

Docsity.com

##### Document information

Uploaded by:
atasi

Views: 840

Downloads :
0

University:
Islamic University of Science & Technology

Subject:
Discrete Mathematics

Upload date:
27/04/2013