Recursion is a technique that leads to elegant solutions to problems that are difficult to program using simple loops. Suppose you want to find all the files under a directory that contain a particular word. How do you solve this problem? There are several ways to do so. An intuitive and effective solution is to use recursion by searching the files in the subdirectories recursively.
H-trees, depicted in Figure below, are used in a very large-scale integration (VLSI) design as a clock distribution network for routing timing signals to all parts of a chip with equal propagation delays. How do you write a program to display H-trees? A good approach is to use recursion.
To use recursion is to program usingrecursive methods—that is, to use methods that invoke themselves. Recursion is a useful programming technique. In some cases, it enables you to develop a natural, straightforward, simple solution to an otherwise difficult problem.
The above is the detailed content of Recursion. For more information, please follow other related articles on the PHP Chinese website!