Computers, Programming
Recursion is what? Recursion in programming (examples)
Recursions are interesting events in themselves, but in programming they are of particular importance in individual cases. For the first time encountering them, quite a significant number of people have problems with their understanding. This is due to the huge field of potential application of the term itself, depending on the context in which "recursion" is used. But you can hope that this article will help to avoid a possible misunderstanding or misunderstanding.
What is "recursion" in general?
What do you mean by recursion in programming?
The recursion can be finite or infinite. In order for the former to stop calling itself, there must also be conditions for termination. This can be a decrease in the value of the variable and when a certain value is reached, call stop and program termination / transition to the subsequent code, depending on the needs to achieve certain goals. Under infinite recursion, it is meant that it will be called while the computer or program in which it is running is running.
It is also possible to organize complex recursion using two functions. Let's say there are A and B. A function has a call in its code B, and B, in turn, tells the computer to perform A. Complex recursions are a way out of a number of complex logical situations for computer logic.
If the reader reading these lines studied the program cycles, then he probably already noticed the similarity between them and recursion. In general, they can actually perform similar or identical tasks. With the help of recursion it is convenient to make an imitation of the work of the cycle. This is especially useful where the cycles themselves are not very convenient. The scheme of software implementation does not differ much from different high-level programming languages. But still the recursion in "Pascal" and the recursion in C or another language has its own peculiarities. It can be successfully implemented in low-level languages like "Assembler", but this is more problematic and time-consuming.
Trees of recursion
- It has an initial special node, which is called the root of the whole tree.
- The remaining nodes are in a quantity different from zero, pairwise disjoint subsets, and they are also a tree. All such forms of organization are called subtrees of the main tree.
In other words: trees contain subtrees that contain trees, but in less quantity than the previous tree. This continues until one of the nodes has the opportunity to move further, and this will indicate the end of the recursion. There is one more nuance about the schematic image: ordinary trees grow from bottom to top, and in programming they are drawn backwards. Nodes that do not have an extension are called end nodes. For convenience of designation and for convenience, genealogical terminology (ancestors, children) is used.
Why is it used in programming?
The differences of recursion in different programming languages
Despite the general implementation scheme and specific application in each individual case, recursion in programming has its own characteristics. This can lead to difficulty while searching for the required material. But you should always remember: if a programming language calls functions or procedures, then the recursion call is a workable thing. But its most significant differences are manifested when using low and high programming languages. Especially it concerns the possibilities of software implementation. Execution ultimately depends on what task is set, in accordance with it, recursion is written. Functions and procedures are used differently, but their goal is always the same - to force themselves to call themselves.
Recursion is easy. How to just remember the content of the article?
Similar articles
Trending Now