Advanced: Recursive Functions

Computer Number Systems

Recursive Functions

A definition that defines an object in terms of itself is said to be recursive. This theoretical mathematical topic serves as an introduction to recursive programming (which is supported by Pascal, but not by most BASICs). It also provides a framework for analyzing algorithms (determining the running time and/or space required) which contain loops or recursive sections.

Many expressions may be defined recursively in a very simple and elegant manner. The art of recursive thinking is an important skill. Applications of recursion appear in many areas of mathematics (factorials, compound interest, difference equations, etc.)

In this round recursive relationships will be shown not in the context of a programming language but usually in functional notation from mathematics or in an algorithmic description.

Consider the following recursive algorithm for painting a square:

  1. Given a square.
  2. If the length of a side is less than 2 feet, then stop.
  3. Divide the square into 4 equal size squares (i.e.,
    draw a “plus” sign inside the square).
  4. Paint one of these 4 small squares.
  5. Repeat this procedure (start at step 1)
    for each of the 3 unpainted squares.

If this algorithm is applied to a square with a side of 16 feet (having a total area of 256 sq. feet), how many square feet will be painted?

recursive1

recursive2