Getting Started

In coding, for loops and while loops are often useful in solving repetative problems. But for loops require that we know ahead of time the exact number of iterations that solving a problem will require. A simple while loop my address that issue, but it still is easy to imagine instances when a while loop alone would not be sufficent. For example, how would you go about programming a binary tree without recursion? Clearly the situation can get pretty hairy quickly.

Think about it...

Take a look at this picture - pretty simple, right? It probably wouldn't take too long for you to draw something similar by hand - its just a set of increasingly small triangles. It's not bad - try it out.

Now that we've established that this is a fairly simple problem, think of how you would code it. Even this simple task is too complicated for a simple for loop or while loop. You have to find the midpoints of each line, draw a triangle, and then that makes three more triangles, so for each one of those three triangles you need to find the midpoints, draw a triangle...and so it grows!