There are a number of ways of creating 3D images. One of the earliest techniques that graphics programmers have used (and one form or another this technique is still used today) actually is a common painting technique. This is probably why this technique is known as the painters algorithm.
If you have watched a professional painter when he or she is painting, especially landscape painters, you will notice that they tend to paint in layers. First they paint a sky and ground. Next they add multiple layers of clouds to the sky painting the furthest away layers first then painting over those layers with closer clouds. After that they add the distant mountains. A few more passes of mountains are then painted, furthest to closest just like they did with the clouds. Distant forest may be painted next. A river may be added at this point to be followed by layers of trees and shrubs painted from furthest to closest. Once the closest layer of grass and shrubs is finished, the painter has a landscape painting completed.
The exact same technique that the artist uses can be applied to computer generated scenes. The problem with this technique is that there is a lot of over-painting being done. This is where more advanced algorithms come into play. With computer graphics, especially more sophisticated 3D rendering, there is potentially a huge amount of information to be drawn. Modern 3D engines will have one or more culling passes. These passes simply remove objects that will not be seen from the list of object to be drawn. In addition, a more advanced version of the painters algorithm, known as z-buffering, is used. Thankfully, most of the culling and drawing optimizations is handled by the Flash player.