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:
- Given a square.
- If the length of a side is less than 2 feet, then stop.
- Divide the square into 4 equal size squares (i.e.,
draw a “plus” sign inside the square). - Paint one of these 4 small squares.
- 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?