Clever Geek Handbook
📜 ⬆️ ⬇️

Recursive function

The recursive function (from lat. Recursio - return) is a numerical functionf(n) {\ displaystyle f (n)} f (n) a numerical argument, which in its record contains itself. This record allows you to calculate the valuesf(n) {\ displaystyle f (n)} f (n) based on valuesf(n-one),f(n-2),... {\ displaystyle f (n-1), f (n-2), \ ldots} f (n-1), f (n-2), \ ldots , similar to reasoning by induction . To make the calculation complete for anyn {\ displaystyle n} n , it is necessary that for somen {\ displaystyle n} n the function was defined non-recursively (e.g. forn=0,one {\ displaystyle n = 0,1} n = 0.1 )

Examples

An example of a recursive function giving the nth Fibonacci number :

F={F(0)=one;F(one)=one;F(n)=F(n-one)+F(n-2),n>one.{\ displaystyle F = {\ begin {cases} F (0) = 1; \\ F (1) = 1; \\ F (n) = F (n-1) + F (n-2), \ quad n> 1. \ end {cases}}} F={\begin{cases}F(0)=1;\\F(1)=1;\\F(n)=F(n-1)+F(n-2),\quad n>1.\end{cases}}

Guided by this record, we can calculateF(n) {\ displaystyle F (n)} F(n) for any positive integer n in finitely many steps. True, along the way you have to additionally calculate the valuesF(n-one),F(n-2),...,F(2) {\ displaystyle F (n-1), F (n-2), \ ldots, F (2)} F(n-1),F(n-2),\ldots ,F(2) .

Closed form

In connection with overhead, it is useful to know if a recursive function has a non-recursive (closed) form.

The closed form may not be found for all recursive functions (relations). For some of them, only approximate closed forms were found. Some recursive relationships, such as factorial , are considered elementary mathematical operations.

For example, a recursive function that describes the sum of numbers in a natural series:

f={f(0)=0;f(n)=n+f(n-one),n>0{\ displaystyle f = {\ begin {cases} f (0) = 0; \\ f (n) = n + f (n-1), \ quad n> 0 \ end {cases}}} f={\begin{cases}f(0)=0;\\f(n)=n+f(n-1),\quad n>0\end{cases}}

can be translated into closed form:f=n(n+one)2 {\ displaystyle f = {\ frac {n (n + 1)} {2}}} f={\frac  {n(n+1)}{2}} .

Applications

Recursive functions play an important role in the theory of algorithms , since many algorithms have a recursive structure.


Source - https://ru.wikipedia.org/w/index.php?title=Recursive_function&oldid=92117498


More articles:

  • Dimuonius
  • Industrial (metro station, Kharkiv)
  • Abol Fatah Khan Zend
  • Central Market (metro station)
  • Feridun Malcolm Khan
  • Bonch-Bogdanovsky, Alexander Mikhailovich
  • Williams, Forman Arthur
  • Frangulov, Sergey Ivanovich
  • Moiseev, Alexander Petrovich (athlete)
  • Kholodnogorsko-Zavodskaya Line

All articles

Clever Geek | 2019